Dave
Always wear safety glasses while programming.
What I usually do when I need to use RANDOM, is to seed it with a 16 bit timer value, and then add a few other variables I've got around and always tie grabbing that random number with some sort of human interaction.
If you've got an event that relies on human interaction somehow (i.e. button press) and a tight loop somewhere, there ain't no way you're going to get a continuously repeatable result.
True, RANDOM in PBP isn't all that random, but when you start adding the 'YOU' factor to it, you can get decent results...
Like maybe use a floating pin or some other means for a spare pin to pick up some "static" to generate an interupt or something?. But there again you may only pick up 60Hz (or 50), but i have heard of people doing this to get random randomness
This has crossed my mind also ( didnt tryed yet though ).Like maybe use a floating pin or some other means for a spare pin to pick up some "static"
I think that you can get decent random results using a spare pin with ADC grabbing nothing but noise.
You can then get 1 ou 2 bits from that "noise" which i believe it would be pretty random.
This is untested, but was thinking of trying it someday....
The theory.
Leave an analog pin floating and take a voltage measurement to use as the seed for the random number.
Not sure how mach variation there will be in each of the measurements. The other thing would be to reduce the sample time for the conversion which may give to less accuracy and give better random results.
Also, if the pin is connected to a wire or long track, it should act as an antenna and increase the variation in the measurements.
Maybe some of the experts around here will have any ideas if this could work
Paul
+-------------------------------------------------------------------+
| PBP 2.47/2.50 | MCS+ 3.0.0.5 | U2 Prog | Vista x64 | NO SLEEP!!!!!!! |
+-------------------------------------------------------------------+
I once did a project that used a DS18B20 temperature sensor. I used this sensor to also make the seed number for the random generator, worked quite well.
Bookmarks