Random Numbers
Daniel_Langkilde
Posts: 2
Hi!
I am trying to use the RANDOM function in PBASIC 2,5 to create series of random numbers. But since the code is psuedorandom i need seed values. In the examples included in the helpfile the initiate the random sequens with the same value over and over again. I want something that changes so I don't get the same values over and over again!
Thnx!
I am trying to use the RANDOM function in PBASIC 2,5 to create series of random numbers. But since the code is psuedorandom i need seed values. In the examples included in the helpfile the initiate the random sequens with the same value over and over again. I want something that changes so I don't get the same values over and over again!
Thnx!
Comments
Step 1: Generate Random Number
Step 2: If button pressed then goto "Step 3", otherwise, goto Step 1
Step 3: Continue with the execution of the rest of your program
Main:
· DO
··· RANDOM lottery
· LOOP UNTIL (StartBtn = Pressed)
We often use this kind of structure to create a random timing delay for a triggered prop.· To create a delay between X and Y, you can do this:
· timer = lottery // (Y - X + 1) + X
... so it you wanted to create a delay between one and five seconds, the actual code would be:
· timer = lottery // 4001 + 1000
· PAUSE timer
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Another possibility might be to base the seed off states of various input pins used for other purposes, if these would be in different and somewhat random states when initializing the random number generator.
This problem of the seed, and the "unrandom" sequence of "random" numbers is not unique to the STAMP.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
John R.
8 + 8 = 10