More random than random()

Arduino
More random than random()

arduinoRandom_cc.jpg

The Arduino random() function can be used to easily generate a seemingly unpredictable series of numbers. The only problem is, from the first time it’s used in a sketch, random() actually begins spitting out the same series of seemingly random numbers. The standard solution to this conundrum is to start (or “seed”) the formula with a noisy reading taken from an unused analog pin like so: randomSeed(analogRead(0)); But for some the data returned by that little trick may still not be random enough, and that’s why Tinker.it created an extra randomy randomabration by the name of TrueRandom

It is hard to get a truly random number from Arduino. TrueRandom does it by setting up a noisy voltage on Analog pin 0, measuring it, and then discarding all but the least significant bit of the measured value. However, that isn’t noisy enough, so a von Neumann whitening algorithm gathers enough entropy from multiple readings to ensure a fair distribution of 1s and 0s.

And if you’re left wondering what all that random is good for, think – games, cryptography, generating serial numbers and similar. Swing by the TrueRandom code repository to download the library.

What will the next generation of Make: look like? We’re inviting you to shape the future by investing in Make:. By becoming an investor, you help decide what’s next. The future of Make: is in your hands. Learn More.

Discuss this article with the rest of the community on our Discord server!

ADVERTISEMENT

Escape to an island of imagination + innovation as Maker Faire Bay Area returns for its 16th iteration!

Prices Increase in....

Days
Hours
Minutes
Seconds
FEEDBACK