Random function evaluating to strange output


#1

I’m trying to create a piston that turns lights at sunset, plus or minus 15 minutes. I’m using the random function (-15 + random(15)) but the evaluation in webcore is giving me very strange numbers, like -420000. Why is it evaluating to that?

How do I create a piston that will run at sunset + or - 15 minutes?


#2

That is -420 seconds, or -7 minutes. Time is represented in milliseconds


#3

Ok, thanks!

I assume that random evaluation is not hard-coded and that’s just the evaluation when it was run at the time?


#4

I am looking at something similar for a piston - so is random random at runtime, or is it randomized once at piston save

My assumption was that if I do (-15 + random(5)) it would be 15m +0-5m each time … so anywhere between 15 and 20m and different each time the piston fires

Am I off base here?


#5

That is an one-off evaluation you see there. Save and click on that task again and you will get a different number. It gets a new number any time it is evaluated, either at build time or at run time.


#6

Correct


#7

I’m genuinely curious… why do you want randomness for lights turning on at sunset? Best presence simulation by less consistency?


#8

I’m genuinely an idiot… I was making a first run at the piston when I ran into my question. I just took a screenshot and posted it. I fixed it after. I also had my timings off for turning on within the correct random range.


#9

Thanks for the beginner code to grab, newbie here. I’m also looking to randomize my two inovelli switches for on between x and y before sunset, and off between x and y time at night.