More random than random?
Arduino has the random() function, that generates random numbers.
Try this code:
int count; void setup() { Serial.begin(9600); Serial.println("Here are some random numbers"); for (count=1; count<=10; count++) { Serial.println(random(100)); } } void loop() { }
I get the numbers 7, 49, 73, 58, 30, 72, 44, 78, 23, 9. You probably did too. Not very random.
Generating truly random numbers in electronics isn’t easy. There are all sorts of problems to solve – where to get the random numbers from. How to make sure they really are even and fair.
We often have need for truly random numbers on Tinker.it! projects, so we wrote a library to do just that. We’ve released it so that others can use it too. TrueRandom is downloadable from our Google Code pages.
So lets try that again, with TrueRandom installed.
#include <TrueRandom.h> int count; void setup() { Serial.begin(9600); Serial.println("Here are some random numbers"); for (count=1; count<=10; count++) { Serial.println(TrueRandom.random(100)); } } void loop() { }
Much better.
We’re looking at using this library for games, ESP experiments, fortune telling, cryptography (generating keys, challenges and nonces) and automatically allocating unique serial numbers (UUID, Ethernet MAC addresses). We’d love to know what you use it for.


