Project Overview
The "Arduino Pseudo-Random Generator" is a fundamental study in computational entropy. While standard computers are deterministic—meaning they follow predictable rules and cannot generate "true" randomness on their own—this project demonstrates how to harvest environmental noise to create a highly unpredictable seed. By utilizing a "floating" analog pin as a source of electromagnetic interference, the Arduino creates a unique starting point for its mathematical random algorithms, ensuring that every time the device is powered on, the sequence of numbers generated is different from the previous session.
I made this by experimenting with the in-built random number generator and then once it was working, I then added the ability to take a floating pin and incorporate that into the equation, And as a result, we have the completely random number generator
Technical Working Principle
- Deterministic vs. Non-Deterministic: Most microcontrollers use a PRNG (Pseudo-Random Number Generator). This is a mathematical formula that produces a sequence of numbers that appear random but are actually pre-computed. If you start the formula with the same number (the Seed), you will always get the same sequence.
- The Floating Pin Method: To break this predictability, the project uses
analogRead(A0)on a pin that is connected to nothing. This is known as a Floating Pin. A floating pin acts like a tiny antenna, picking up stray electromagnetic noise from the power lines, the user's body, and the surrounding environment. This noise is highly variable and unpredictable. - Seeding the Generator: In the
void setup(), the code callsrandomSeed(analogRead(A0));. By reading the instantaneous voltage of the atmospheric noise, the program "jumps" to a random starting position in its mathematical sequence. This is a critical engineering step for games, encryption tests, or any application where repeated patterns would be undesirable. - The
random()function: After seeding, therandom(min, max)function can be used to generate values within a specific range. Because the seed was non-deterministic, the resulting values fulfill the requirements of "unpredictability" for most hobbyist and educational projects.
Engineering Insights & Limitations
- Resolution of Noise: The Arduino's ADC (Analog-to-Digital Converter) has a 10-bit resolution (0 to 1023). While this provides 1,024 possible seed values, true high-security applications would require combining multiple readings or "hashing" the noise over time to increase entropy.
- EMI Influence: In a high-interference environment (near a large motor or radio transmitter), the floating pin might display a predictable 50/60Hz oscillation. In such cases, more advanced engineers might use the Jitter between the internal watchdog timer and the crystal oscillator to generate even higher-quality entropy.
- Applications: This technique is essential for creating digital dice, random light patterns, or "shuffling" playlists in embedded music players.