An Arduino-based random number generator
A random number generator gadget built on Arduino. It’s way over-engineered and that is how I like it.
Randuino is a gadget that produces pseudo-random numbers and displays them on an LCD screen. It’s built on the Arduino platform. It’s functional, but not ready for actual use.
The goal is to have a ruggedised random number tool for scientific fieldwork, one that I don’t have qualms giving to other students, and which can take the place of the random number app on my phone. I could use a printed random number table, but that is nowhere near over-engineered enough for me.
The Arduino’s documentation suggests that its analog pins can detect the field of cosmic/microwave/radio waves around us, express it as a number from 0–1023, and then use that number as the seed for random number generation. However, I’ve noticed that the seed value generally ranges from 100-500. I’ve tried to extend that range by using the seed value to randomly produce another seed, which is then used as the actual seed for producing the random numbers that are displayed to the user. Phew!
Note: All of this stuff (except for the 110 Ω resistor) can be found in the official Arduino Starter Kit. You can use one of the included potentiometers instead.
// Random number generator v0
// Desi Quintans (desiquintans.com/randuino)
#include <LiquidCrystal.h>
LiquidCrystal lcd(4, 5, 6, 7, 8, 9);
const int seedPin = A0;
const int button = 2;
int buttonState;
int prevButtonState;
int totalNumbersGenerated = 0;
void setup() {
lcd.begin (16,2);
pinMode (seedPin, INPUT);
pinMode (button, INPUT);
int randSeed = analogRead (seedPin);
int generatedSeed = random (-randSeed, randSeed);
randomSeed (generatedSeed);
prevButtonState = digitalRead (button);
PrintToLcd (
"Rng: " + String (-randSeed) + " - " + String (randSeed),
"Seed: " + String (generatedSeed)
);
}
void loop() {
buttonState = digitalRead (button);
if (buttonState != prevButtonState && buttonState == HIGH)
{
totalNumbersGenerated++;
PrintToLcd (
"Result #" + String (totalNumbersGenerated),
String (random (-999999999, 999999999))
);
delay (200);
}
prevButtonState = buttonState;
}
void PrintToLcd (String line1, String line2)
{
lcd.clear ();
lcd.print (line1);
lcd.setCursor (0, 1);
lcd.print (line2);
}
This thing is at a preliminary stage, and I’m documenting it here so that I can do other things with my only Arduino, and reassemble this later. Things I’d like to implement later are: