If it is called at the same point after boot everytime, it may not be so random. It should be triggered by some event, or use the Random Number Generator Object that Chip recently posted, which likely needs modifying with limits in your case.
If you have any loops in your program where you wait for an external event whether it's a keypress or button press or a serial input character, put "myvar?" in the loop. This will "stir" the random sequence in a way that's dependent on the "hard to predict" external event.
Comments
myvar is your variable that holds the random number
random is the resulting random number from 0 to 22
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Parallax Forums - If you're ready to learn, we're ready to help.
Post Edited (TChapman) : 3/27/2007 8:10:07 PM GMT
http://forums.parallax.com/showthread.php?p=639978
It takes 32 longs of code space and 2 longs for variables. It takes one cog, but you only need to run it when you need a new random number:
OBJ
· rr : "RealRandom"
PRI random_0_to_22 : value
· rr.start
· value := ||rr.random // 23
· rr.stop
This will never yield a repeating pattern.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chip Gracey
Parallax, Inc.
Post Edited (Chip Gracey (Parallax)) : 3/27/2007 9:05:57 PM GMT