Random number between two values


#1

I want to create a rule like this:

every day, at 10 minutes before sunset
do

However, I want the value 10 for minutes to be a variable that can be a random number between 5 and 25. Is there anyway this can be done?


Picking a Random Value from 'Color' and 'Color Temperature'
#2

To output a random integer between 5 and 25 use:
(5 + random(20))
(This does a random number between 0-20, then adds 5)

More info can be found here:
https://wiki.webcore.co/Functions#random


#3

image

Modify something like this.

EDIT. Above beat me to it.


#4

I use random for my “away lighting”…makes it look like someone is shutting the lights of at a different time every night.


#5

Is there a way to take that random number and store it into a variable and then somehow make sure the new random number isn’t the same as the stored one?


#6

I’m trying to use the random syntax mentioned above. First i tried offsetting by -20 minutes and as in the screen shot below and this creates a statement saying: every day, at 20 minutes before sunset

However, when I tried using the random syntax as pictured below, it says every day, at sunset +/- the random number. So not sure what I am doing wrong, the random number should also read every day, at x minutes before sunset


#7

I think your last screenshot looks right.
It should work


#8

I use the following snippet so I don’t get the same random color for my color rotation. In your case, store the last set of numbers used in lastRandom variable, then use nextRandom variable in your offset.

repeat
do
  set variable nextRandom = your_expression
until
  nextRandom is not lastRandom
end repeat

#9

problem with the last screenshot is that it doesnt know whether that random number is before or after sunset. whereas my first screenshot clearly says before sunset.


#10

Inside the curly brackets it says minus, so it looks right to me. Have you tested it?

You can do a quick test (without waiting for tomorrow) by selecting the expression like in this pic:
temp
Ctrl-X (to cut) … then Ctrl-V (to paste)
You should see the numbers in the grey area change each time.
(Always between -25 and -5)