View Full Version : Random Number Generator
09-07-2008, 12:44 AM
I need some help with the random function on basic stamp 2se
My question is if there is a way to generate a random 2 digit number like 1 to 99 is so how would I do it with the random function?
Thanks in advance
09-07-2008, 02:03 AM
First you use the random function to produce a random number between 0 and 65535, then you use the modulus operator (//) to get the remainder of a division in the range you want. If the random variable used by RANDOM is R and you want a result between 1 and 99, you
would compute "(R // 99) + 1". This would first give you a remainder between 0 and 98, then add one to that to give you a value between
1 and 99 inclusive.
Phil Pilgrim (PhiPi)
09-07-2008, 02:04 AM
B2 = W0 // 99 + 1
'Still some PropSTICK Kit bare PCBs (http://forums.parallax.com/showthread.php?p=729096) left!
09-07-2008, 09:01 AM
Thanks a lot guys.