Need Some Help With Real random Class.. and random timer.
Anubisbot
Posts: 112
Hi i need to trigger 4 Pub's at different random times.
I tried the random object form the OBEX
but dint had to much luck with it. i need to start the Pub's randomly so the time span i need is from 30 sec. to 300 sec.
I hope some one has a good idea how to solve this, maybe i am blind
but i searched for it and count find any thing
Best regards Anubisbot
I tried the random object form the OBEX
but dint had to much luck with it. i need to start the Pub's randomly so the time span i need is from 30 sec. to 300 sec.
PRI Main_Loop dira[noparse][[/noparse]11..0]~~ RR.Start Time:= RR.Random Time2:= RR.Random Time3:= RR.Random Time4:= RR.Random repeat If Time == 0 Small_1_Left repeat until time > 5000000 Time:= RR.Random If Time2 == 0 Small_2_Left Time2:= RR.Random If Time3 == 0 Small_3_Left Time3:= RR.Random Time-- Time2-- Time3-- Time4--
I hope some one has a good idea how to solve this, maybe i am blind
but i searched for it and count find any thing
Best regards Anubisbot
Comments
Leon
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Amateur radio callsign: G1HSM
Suzuki SV1000S motorcycle
The random object generates a number in a range from 0 to ~4billion. As you do a lot of SPIN stuff inside of your loop this can take a while and I don't see any code that ensures the time being between 30 and 300s.
Time1:=30 + RR.Random & $FF···· ' would be a fast solution where the range is between 30 and 285 if that's fine for you
Time2:=RR.Random
Time2:=30 + Time2 & $FF + (Time2 & $F00) >> 8··· ' is randomly adding another 15, so the range is between 30 and 300, but it's a bit slower ... but hey, we talk about seconds ;o)
Now you sould use waitcnt to wait for seconds:
·As I used the case statement you should make sure that not two times have the same value.