True random numbers come from physical processes—like radioactive decay, atmospheric noise, or thermal noise—rather than from a computer algorithm. Unlike pseudo-random numbers generated by software, true random numbers are unpredictable and not repeatable. This guide shows you practical ways to generate them, from using online services to building your own hardware generator. You’ll need a computer with internet access for most methods, and for the DIY approach, some basic electronic components.
What You’ll Need
- A computer with internet access (for online services)
- A web browser (Chrome, Firefox, Edge, etc.)
- For hardware method: a microcontroller (like Arduino), a breadboard, jumper wires, a resistor, and a photoresistor or a simple transistor
- For software method: a programming environment (Python, JavaScript, etc.) if you want to code your own
Step-by-Step
- Use an online true random number service. The easiest method is to visit a website that generates true random numbers from physical sources. For example, the RANDOM.ORG service uses atmospheric noise. Go to
random.org, choose the “Integers” generator, set your range (e.g., 1 to 100), and click “Generate.” The numbers you get are based on real atmospheric measurements, not an algorithm. - Download a random number file from a trusted source. Some services offer downloadable files of pre-generated true random numbers. For instance, RANDOM.ORG has a “Pregenerated Files” page where you can download a set of random integers or bitstrings. These files are generated from true randomness and can be used offline later.
- Use a hardware random number generator (HRNG) on your computer. Many modern CPUs and operating systems have built-in hardware random number generators. For example, Intel’s RDSEED instruction and Linux’s
/dev/randomdevice use hardware entropy. To access this on Linux, you can simply read from/dev/randomusing a command likeod -An -N4 -tu4 /dev/randomto get a 4-byte random integer. On Windows, you can use PowerShell:Get-Random -SetSeed (Get-Random)is not true random, but you can use the .NETRNGCryptoServiceProviderclass to access system entropy. - Build your own true random number generator with an Arduino. If you want full control, you can create a simple hardware RNG. Connect a photoresistor (light-dependent resistor) in a voltage divider circuit to an analog input pin on an Arduino. The ambient light fluctuations produce noise. Read the analog value repeatedly (e.g., 1000 times) and use the least significant bits of each reading. Combine these bits to form a random number. Here’s a basic sketch:
// True random number generator using analog noise // Connect photoresistor between 5V and A0, with a 10k resistor from A0 to GND. void setup() { Serial.begin(9600); randomSeed(analogRead(0)); // Not true, but helps initial state } void loop() { uint32_t randomBits = 0; for (int i = 0; i < 32; i++) { // Read the analog value, take the LSB, shift into a buffer int val = analogRead(A0); randomBits = (randomBits << 1) | (val & 1); delay(1); // Allow time for noise to change } Serial.println(randomBits); delay(1000); }This reads the analog voltage, which fluctuates due to light and electrical noise, and extracts the least significant bit to build a 32-bit random number.
- Use a radioactive decay source (advanced). For a more scientific approach, you can use a Geiger-Müller tube connected to a computer. Each detection event is random. This is how some high-end RNGs work, but it's not practical for most people. If you have access to a Geiger counter with a serial output, you can read the timestamps of events and use the timing differences to generate random bits.
- Combine multiple sources for better entropy. For cryptographic purposes, you can mix several entropy sources. For example, take the output from an online service, your CPU's RDRAND, and your own hardware generator, then XOR them together. This reduces the risk of any single source being compromised.
Common Mistakes
- Using pseudo-random generators thinking they are true. Functions like
Math.random()in JavaScript orrand()in C are pseudo-random. They are deterministic and can be predicted if you know the seed. True randomness requires a physical source. - Ignoring the quality of the entropy source. For example, using a microphone's ambient noise might be predictable if the environment is quiet. Always test the output for patterns or biases.
- Not debiasing the output. Physical sources often have biases (e.g., more 1s than 0s). Use a debiasing technique like the von Neumann extractor: take pairs of bits, discard 00 and 11, and keep 01 as 0 and 10 as 1. This ensures a uniform distribution.
- Assuming online services are always available. If you rely on an external service, you need internet access. For offline use, consider downloading a pre-generated file or building your own hardware.
- Using the same seed for multiple runs. In programming, if you seed a pseudo-random generator with the same value, you get the same sequence. True random numbers don't have this issue, but if you're mixing, be careful.
Tips
- Test your numbers for randomness. Use simple statistical tests like the chi-square test or the runs test. You can also use tools like
ent(a Unix utility) to analyze a file of random bytes. - Use a cryptographic library for production. If you need true random numbers for security, use a well-vetted library like OpenSSL's
RAND_bytes()or the .NETRNGCryptoServiceProvider, which use hardware entropy sources under the hood. - For Arduino, use a better noise source. Instead of a photoresistor, you can use a reverse-biased transistor's avalanche noise, which is more random. Search for "avalanche noise generator" for schematics.
- Consider using a dedicated USB RNG device. Devices like the "OneRNG" or "Entropy Key" plug into your computer and provide a steady stream of true random numbers. They are affordable and reliable.
- Store your random numbers securely. If you generate a batch, keep them in a safe place, especially if you use them for encryption keys. Once used, do not reuse them.
Troubleshooting
- Online service is not loading. Check your internet connection. If the site is down, try an alternative like
randomnumbergenerator.comor use a pre-generated file. - Arduino sketch produces constant values. This usually means the analog input is not changing. Check your wiring: ensure the photoresistor is exposed to varying light, and the resistor value is correct (10k is typical). Also, try wiggling the wires or moving your hand over the sensor.
- Your numbers look biased (e.g., all 1s or all 0s). Apply a debiasing algorithm. If you're using the Arduino code, you might need to increase the delay between readings to allow more noise variation, or use a more sensitive sensor.
- The
/dev/randomcommand hangs. On Linux,/dev/randomcan block if the system entropy pool is depleted. Use/dev/urandominstead, which is non-blocking, though it's technically pseudo-random but seeded with true entropy. - PowerShell random number is not true random. The default
Get-Randomuses a pseudo-random algorithm. To get true randomness, use[System.Security.Cryptography.RandomNumberGenerator]::GetBytes()to fill a byte array.
Frequently Asked Questions
- What is the difference between true random and pseudo-random?
True random numbers come from physical processes that are inherently unpredictable, like radioactive decay. Pseudo-random numbers are generated by algorithms that are deterministic but appear random. With the same seed, a pseudo-random generator will produce the same sequence. - Can I generate true random numbers without any hardware?
Yes, you can use online services that rely on physical sources (like atmospheric noise). However, you need internet access. For offline, you would need some hardware source or a pre-generated file. - Is the random number from my computer's
random()function true random?
No, it's pseudo-random. However, many operating systems have a system entropy pool that is seeded from hardware sources, and functions likerandom()may use that seed, but the sequence is still deterministic once seeded. - How do I know if a random number is truly random?
You can't know with certainty just by looking at a single number. Statistical tests over many numbers can indicate randomness, but true randomness is about the source, not the output. If the source is physical and unpredictable, it's true random. - Can I use true random numbers for encryption?
Yes, true random numbers are ideal for cryptographic keys because they are unpredictable. However, you must ensure the generation process is secure and the numbers are kept confidential. - Is it legal to use a radioactive source for random number generation?
In most places, owning a small radioactive source (like a check source for a Geiger counter) is legal, but you must follow safety regulations. However, for most purposes, simpler sources like noise are sufficient and safer.
Related
- COUNTA in Google Sheets: Count Non-Empty Cells
- How to Replace a Value in a Python Dictionary
- Solar Battery Calculator App: How to Size Your System
Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.
More in How-to basics
- How to Create a Distribution List in OutlookTo create a personal distribution list in Outlook, open People, choose New Contact Group in classic Outlook or…
- Excel Box Plot Explained: Create and Read OneAn Excel box plot, also called a box-and-whisker chart, summarizes how a set of numbers is distributed: its…
- Dictionaries Python 3 Update: What Changed and How to Use ItIn Python 3, dictionaries are insertion-ordered by default (since 3.7 as a language guarantee), support dictionary union operators…
- Goal Seek in Excel: Find the Input for a TargetGoal Seek in Excel finds the value a single input cell must have to make a formula cell…
- Excel Save As Shortcut: Windows, Mac, and WebIn Excel for Microsoft 365 on Windows, press F12 to open the Save As dialog. On a Mac,…
- How to Convert Data to a Range in ExcelConverting data to a range in Excel turns a table back into a normal range of cells. This…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.