Random number generator: how they work, uses, and free tool

8 min read

Generate random numbers in any range. Learn the difference between true random and pseudorandom, and uses in lotteries, games, and statistics.

What is a random number and why it's hard to generate

A random number is an unpredictable value following no pattern. Generating true randomness is one of computing's hardest problems.

Why hard: Computers are deterministic. They need external entropy (mouse movement, electronic noise) or algorithms simulating randomness (pseudorandom).

Real consequence: In 2006, a Debian random generator bug weakened ALL SSL keys generated in 2 years. Only 32,768 possible keys instead of billions.

Generate with the NexTools number generator.

True random vs pseudorandom (PRNG vs TRNG)

TRNG: Physical phenomena (radioactive decay, thermal noise). Unpredictable. Used by random.org, Intel RDRAND. Slow.

PRNG: Mathematical algorithm from a seed. Fast, reproducible. Math.random() uses xorshift128+.

CSPRNG: PRNG designed to be unpredictable even knowing previous outputs. crypto.getRandomValues(), /dev/urandom. For security.

TypeSpeedPredictableUse
TRNGSlowNoHigh-level crypto
PRNGFastWith seedGames, simulations
CSPRNGFastNo (practical)Passwords, tokens, keys

Real-world uses of random numbers

1. Lotteries/raffles: Fair selection from N participants.

2. Games: Dice, cards, world generation, loot drops. The NexTools dice roller uses this.

3. Statistics/sampling: Random samples from populations. Clinical trials assign patients randomly.

4. Cryptography: Keys, tokens, nonces, IVs.

5. Monte Carlo simulation: Finance, physics, engineering.

6. Passwords: The NexTools password generator uses CSPRNG.

How to use the NexTools number generator

The NexTools generator: define range (min/max), choose quantity, allow/disallow duplicates, generate. Uses CSPRNG (crypto.getRandomValues). All in browser.

Uniform distribution: why fairness matters

Uniform = every number has EXACTLY equal probability.

Common code error: Math.floor(Math.random() * 10) has slight bias due to floating point. For most uses imperceptible, for crypto unacceptable.

Correct method: Rejection sampling with crypto.getRandomValues().

Verify by generating 10,000+ numbers and counting frequencies. Use the percentage calculator.

Random numbers in programming

JavaScript: Math.random() (PRNG), crypto.getRandomValues() (CSPRNG).

Python: random.randint() (PRNG), secrets.randbelow() (CSPRNG).

Bash: shuf -i 1-100 -n 1, $RANDOM (0-32767).

Rule: Games/UI → Math.random(). Security → crypto/secrets.

Seeds and reproducibility

PRNGs use a seed. Same seed = same sequence.

Want reproducibility: Testing, procedural generation (Minecraft), scientific simulations.

Don't want: Security (unpredictable seed), lotteries, gambling.

For unique IDs, the NexTools UUID generator uses cryptographic randomness.

Paradoxes and curiosities about randomness

Birthday paradox: 23 people → >50% chance two share a birthday.

Humans aren't random: Asked to pick 1-10, most choose 3 or 7. Asked for random coin sequence, humans avoid long streaks (but real randomness has them).

Lottery: Powerball odds: 1 in 292 million. Need 1 ticket/second for 9.3 years to cover all.

Pi is "random": Pi's digits pass all randomness tests but are completely deterministic.

Try this tool:

Open tool

Frequently asked questions

Is Math.random() truly random

No. Pseudorandom (xorshift128+ in V8). Deterministic from a seed. Fine for games/UI. For security use crypto.getRandomValues().

How do I generate a random number in a specific range

JS: Math.floor(Math.random() * (max - min + 1)) + min. Python: random.randint(min, max). Or use the NexTools generator.

Can I use random numbers for a fair lottery

Yes if the generator is uniform and non-manipulable. For legal lotteries, use verifiable generators (random.org with cryptographic signatures).

What is a seed in random generation

Initial value determining the entire pseudorandom sequence. Same seed = same sequence. For security, seed must be cryptographically unpredictable.

What's the difference between PRNG and CSPRNG

PRNG: fast but predictable with known seed. CSPRNG: designed to be unpredictable even knowing previous outputs. Use CSPRNG for security.

Can I generate numbers without repetition

Yes. NexTools has a no-duplicates option. In code: generate array, Fisher-Yates shuffle, take first N.