Page 1 of 1
Random Timer JS script.
Posted: Wed Mar 16, 2022 8:09 am
by FATALES
I don't know how to do it, it doesn't work. I don't know if the numbers can be less than 1000 ms.
It worked with random number generation but I don't want it.
- randomdsna.jpg (172.58 KiB) Viewed 889 times
Re: Random Timer JS script.
Posted: Wed Mar 16, 2022 10:53 am
by edger477
in eval for timer there should be 'random_item(items)' - that one will return integer value that can be used as duration
Re: Random Timer JS script.
Posted: Wed Mar 16, 2022 1:24 pm
by kerkersklave
So what you want to do, is randomly select one of the durations in items for the timer?
The eval-expression has to return a value in milliseconds, not a list of values, so you have to select the element yourself. Selecting an element randomly with equal distribution can be done like this:
Code: Select all
items[Math.floor(Math.random() * items.length)]
Math.random() returns a number between 0 (inclusive) and 1 (exclusive) equally distributed. Math.floor() rounds down to the next integer.
Re: Random Timer JS script.
Posted: Thu Mar 17, 2022 2:26 am
by spaisin
The image looks like you have just 'items' as the eval for the Timer? It seems you should be using random_item(items) instead - to actually call the function you've just created.
Although that relies on my non-eos-specific understanding of scopes, but ..
Re: Random Timer JS script.
Posted: Thu Mar 17, 2022 1:10 pm
by FATALES
fully functional:
- randomtiem.jpg (187.93 KiB) Viewed 521 times