Trouble generating Random Numbers...
CreamPuff
Posts: 1
Hi I am working on a slot machine program that will utilize 4 random numbers and display them in the Debug terminal...getting·random numbers seem to be a real challenge since all i know is what is contained in the "Whats a MicroController" handbook and in the help index...which really didnt help much. I also need to figure out how to make the numbers cycle in the debug terminal...to·imitate a real slot machine...thanks for any help you can give...
Comments
So firstly you need to vary the seed before you call the random statement. One way is to increment a number in a loop, when you jump out of the loop some number is passed to the random statement which returns your random number series. To increase the possible variation in the "seed" ·number I used a word variable that counts to 65535 and back to zero·and continually·repeats until an input (IN0) is taken high which breaks the loop.
To derive the range of numbers I have used the modulo· seed // 10 and added 1 which in the example gives a range of 1 to 10
seed VAR Word
rnd VAR Word
main:
· DO WHILE IN0<1
··· seed=seed+1
· IF seed >65535 THEN
··· seed=0
· ENDIF
· LOOP
· RANDOM seed
· rnd=seed//10+1
· DEBUG DEC rnd," "
GOTO main
Jeff T.