My teacher gave us an assignment I need some help.
StandoffCape
Posts: 4
in BASIC Stamp
Okay, so we made a random number generator, but we keep getting the same numbers every time we run the program. We know that to change the numbers you need to change the seed value, but our teacher won't let us change it every time we run the program. Is there a way to make the program automatically say add one to the seed every time? Thanks any help is appreciated.
Comments
An R and a C on an input pin can be made to give an uncertain number with the RCtime command, especially if you make poor wiring, that is, long and loopy, or use a photosensitive device in place of the R.
How are you generating your random number and does your program run once or keep repeating?
It is best if you can post your program because maybe there is an error in it.
Here is my code.
The idea is that the Stamp waits as long as necessary in the DO loops, until the user has pressed and then released the button. PulseCount will be the last residual value from RCTIME, and that can be the seed.
If the device is connected to a computer, you could ask the user to press a random key on the keyboard, and use that as a seed.
You could use one of the circuits and code shown on page 364, with a temperature sensor (thermistor) or light sensor (LED connected backwards), to give an environmentally determined seed.
I take it that result1 and result2 will be Random numbers.
Is there a particular range of values they need to be in?
Also, why do you have 2 FOR...NEXT loops that go from 1 to 1 since nothing will change?
Is this code being run on a Boe-Bot because I see you are sending what look to be servo pulses using 2 FOR...NEXT loops.
Also, I am guessing that you want one set to run when the 2 magic numbers come up and then other set to run when they don't, so put an ELSE before the 2nd FOR...NEXT loop.
The GOTO If_Then does nothing since If_Then follows that line and it's good practice to avoid using GOTO.
In addition to the BASIC Stamp Manual, you should also look at the What's a Microcontroller and StampWorks texts.
https://www.parallax.com/sites/default/files/downloads/27218-Web-BASICStampManual-v2.2.pdf
https://www.parallax.com/sites/default/files/downloads/28123-Whats-a-Micro-v3.0.pdf
https://www.parallax.com/sites/default/files/downloads/27297-StampWorks-Manual-v2.1.pdf