Random command issue?


#1

Hi it says on the wiki that if i use (2700 + random(3000)) i should get a random value between 2700 and 3000 but i’m getting 4000 numbers. what am i doing wrong?


#2

one too many zeros in the random range.


#3

O, OK how do i do it then, its a kelvin temperature so needs to be them numbers. :frowning_face:


#4

sorry, wasnt clear enough. do this: (2700 + random(300))


#5

so what does that mean?
syntax wise


#6

random(x) will give you a number between 0 and x. Add that to the 2700 and you get a number between 2700 and 2700+x. Make x 300 and that is now 2700-3000


#7

someone’s taking time off from android app i see :wink:


#8

Birthday party tonight. Not mine, of course :wink:


#9

so if x was 400 it would be 4000?
would that also mean
if x was 30 it would be 300?

edit:
so how would you do between 0 and 3?


#10

ahh, in between doing setup work for the party - a quick post from the mobile. got it. :smile:


#11

you definitely work hard, so you should play hard :grinning:


#12

2700 + random(300) = 2700 + [0 … 300] = max value of 3000
2700 + random(1300) = 2700 + [0 … 1300] = max value of 4000


#13

:thinking::sweat::sob::scream:
makes me even more confused

edit:

wait so its not between 2 numbers its 2700 + 300 so 2700 and 3000.

so 2500 + 500 would also be 3000

and that would mean my syntax of (2700 + random(3000)) actually ment between 2700 and 5700?


#14

How about using random(min, max) instead? Just provide the min value you want and the max value. Forget about 2700 + …

For example, random(2700, 3000) would return random values between 2700 and 3000.


#15

your edit is right on.

you do something like y + random(x) = z because you dont want the resulting value of z to be less than y. where y in this is 2700, which is often the lowest color temperature supported by a lot of connected bulbs.


#23

Ok is that because its then a integra and the numbers are not in " " so then it means min and max? But if it was random(“2700”, “3000”) it would have picked one of the numbers? Because I also use random for text strings and then it picks a random one.

I have got it working now, with (2700 + random (300) ), I misunderstood the equation before. I thought from how I read the wiki that ment between 2700 and 300. Makes complete sense now, I did wonder what the + did :smile:

I will try the Min max one next time :stuck_out_tongue_winking_eye:


#24

It appears this does not work as intended. Will need to update webCoRE to allow min and max


#25

I did try this earlier and it just did a random between just the 2 numbers so just used the other random function now i know how it works! :wink: