In SX Microcontrollers, SX/B Compiler and SX-Key Tool, Electronegativity wrote: Hi all, I came up with a simple way to generate random numbers in hardware for the SX, Basic Stamp, or Propeller. All you need is one resistor, one capacitor, and one pin from the device. 1. Set up the resistor and capacitor in parallel between the pin and ground. 2. Set the pin to output and high voltage. 3. Set the pin as an input and count the clock cycles it takes for the voltage to reach the logical transition. 4. Use the least significant bit of the count as a coin flip. Once you have random coin flips you can make any random number, for example 8 in a row give a random # from 0 to 255. For the basic Stamp the RCTIME command will work, or for the SX you can enable the RTCC. The randomness comes from the noise inherent in the circuit. As long as the RCTIME is long compared to the clock speed, the logical transition will be brought about by a noise induced fluctuation. It is best to use TTL logic level for this because the slope of the exponential decay is flatter towards lower voltages, which makes it more likely that a random voltage fluctuation will bring about the transition. This works quite well, and the only disadvantage I can see is that you need to wait many clock cycles per random bit. One solution would be to have it run in the background as an interrupt. You could run it as a debouncing method that also generates random numbers. One millisecond wait after a button push would effectively debounce the contact and give you time to generate digits. The random bits could also be used to seed a psuedo random generator. In any case it's cheap, easy, and it works for me. :smile: ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=167121 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2007 (http://www.dotNetBB.com)