random number generator
Mr. Richard
Posts: 51
I am trying to add a random timing event to a code for a BS2. I am sure that this is well documented, but I could not find it.
Is there a way to create a random number for a counter? I would like to randomize a pause before an event (pause 1-5 seconds then high X) How do I use a random number in a loop?
Thanks for the help
Josh
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Magic Smoke Theory of Electronics –
Inside every electronic part there is magic smoke.
The magic smoke is what makes everything work.
If you release the magic smoke, the part stops working!
Is there a way to create a random number for a counter? I would like to randomize a pause before an event (pause 1-5 seconds then high X) How do I use a random number in a loop?
Thanks for the help
Josh
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Magic Smoke Theory of Electronics –
Inside every electronic part there is magic smoke.
The magic smoke is what makes everything work.
If you release the magic smoke, the part stops working!
Comments
Please see the RANDOM command in the Help File or the BASIC Stamp manual. The RANDOM command randomizes a variable. The trick is to make sure the command is within the loop and the results will be better if the loop runs an arbitrary number of iterations, such as until a button is pressed or some other event. I hope this helps. Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
seed VAR Word
rnd VAR Word
time VAR Word
main:
DO WHILE IN1>0
··· seed=seed+1
· IF seed >65535 THEN
··· seed=0
· ENDIF
LOOP
RANDOM seed
rnd=seed//5+1
DEBUG DEC rnd," "
time = rnd *1000
PAUSE time
GOTO main
Jeff T.