Ramdom numbers
Brian Carpenter
Posts: 728
in order to test my project i need to have my stamp generate a number randomly between 1 and 4 every 3 seconds or so. Doesnt have to be exact. i am just having issues with the random part. how would i write this code.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It's Only A Stupid Question If You Have Not Googled It First!!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It's Only A Stupid Question If You Have Not Googled It First!!
Comments
Main:
· DO
··· RANDOM randVal
· LOOP UNTIL (Select = Pressed)
· selection = randVal // 4 + 1
· ' rest of your code here
· GOTO Main
'Select' is the button definition (PIN) and 'Pressed' is the button state when pressed (1 or 0).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It's Only A Stupid Question If You Have Not Googled It First!!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
I know some people that seed off of variations of the system clock (on computer code)- this still isn't *true* randomness, but since it is then dependent on when you start the program and variations from the system clock it can appear very random indeed.
Ryan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Ryan Clarke
Parallax Tech Support
rclarke@parallax.com
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It's Only A Stupid Question If You Have Not Googled It First!!