Random Number Generator

Generate random integers or decimals within any range. Supports multiple quantities and different distribution types. Instant free results.

n

Enter your values above to see the results.

Tips & Notes

  • For reproducible results: use a fixed seed. For unpredictable results: use a time-based seed.
  • Generating n random integers from range a to b: result = a + floor(random() × (b−a+1)).
  • Shuffling a list: Fisher-Yates algorithm guarantees each permutation is equally likely.
  • For cryptographic use (passwords, keys): use the system CSPRNG, not a basic PRNG.
  • Large sample sizes reduce statistical fluctuation. 10 coin flips may give 8 heads; 10,000 will be closer to 50%.

Common Mistakes

  • Using a predictable seed (like timestamp in seconds) for security — attackers can guess the seed.
  • Assuming pseudorandom = truly random for cryptographic purposes — use CSPRNG for security.
  • Modulo bias: using random()%n for small n with large PRNG range creates non-uniform distribution.
  • Not seeding the PRNG — many generators default to seed 0 and produce the same sequence every run.
  • Expecting random numbers to be evenly spread in small samples — clustering is normal and expected.

Random Number Generator Overview

A random number generator produces numbers with no predictable pattern across the specified range — each output is statistically independent of the previous one. Computers cannot generate true randomness from deterministic circuits alone, so they use pseudorandom number generators (PRNGs) that produce sequences indistinguishable from true randomness for all practical purposes, seeded from entropy sources like hardware timing, mouse movement, or dedicated hardware noise.

Uniform random integer — the most common use:

Random Integer ∈ [min, max] — each integer in the range equally likely
EX: Random number 1–100 → each of the 100 integers has exactly 1% probability of appearing on any given call
Probability of any specific outcome:
P(specific value) = 1 / (max − min + 1)
EX: Rolling a die (1–6): P(4) = 1/6 ≈ 16.67% | Lottery (1–49): P(any one number) = 1/49 ≈ 2.04%
Expected occurrences of any value after n draws:
EX: Drawing from 1–10, 100 times → expected occurrences of any specific number = 100 × (1/10) = 10 times on average (actual results vary due to randomness)
Pseudorandom generators start from a seed value and apply a deterministic algorithm to produce each subsequent number. The Mersenne Twister algorithm (used in Python, NumPy, and many other systems) has a period of 2¹⁹⁹³⁷ − 1 — longer than the number of atoms in the observable universe — and passes virtually all statistical randomness tests. Given the same seed, it produces the identical sequence every time: this reproducibility is a feature in scientific computing for repeatable experiments, but a vulnerability in security applications. Monte Carlo simulation relies entirely on random number generation. Estimating π: generate random points (x, y) in the unit square. Count those where x² + y² ≤ 1 (inside the quarter-circle). The ratio × 4 approximates π. With 1 million points the estimate is accurate to about 3 decimal places — accuracy improving as the square root of the number of samples. Shuffling algorithms depend critically on random number quality.

Frequently Asked Questions

True random numbers come from physical processes like radioactive decay, atmospheric noise, or quantum effects — genuinely unpredictable. Pseudorandom numbers are generated by deterministic algorithms starting from a seed value — they appear random but are reproducible if you know the seed. Computers typically use pseudorandom generators (like Mersenne Twister or PCG) for most applications. For security and cryptography, cryptographically secure pseudorandom number generators (CSPRNGs) are used, drawing entropy from hardware sources.

The most common algorithm is the Mersenne Twister (MT19937), with a period of 2^19937 − 1 — so long it effectively never repeats. It passes most statistical randomness tests but is not cryptographically secure — an attacker who observes 624 consecutive outputs can predict all future outputs. For cryptographic applications, use /dev/urandom on Linux, CryptGenRandom on Windows, or platform CSPRNGs that collect entropy from hardware timings, mouse movements, and other unpredictable sources.

To generate uniform random integers in [min, max]: floor(random() × (max − min + 1)) + min, where random() produces a float in [0,1). Example: random integer from 1 to 6 (dice) = floor(random() × 6) + 1. For floating-point: min + random() × (max − min). Avoid the common mistake of using modulo: rand() % 6 introduces bias when RAND_MAX+1 is not a multiple of 6 — some values appear slightly more often than others.

The Birthday Problem: in a group of just 23 people, there is a >50% probability two share a birthday. This counterintuitive result comes from the number of pairs: 23 people have C(23,2) = 253 pairs. Each pair has a 1/365 chance of matching. P(at least one match) = 1 − (364/365)^253 ≈ 50.05%. By 70 people, the probability exceeds 99.9%. Random number generators must have very long periods to avoid this type of collision in applications like hash tables and simulation.

Monte Carlo methods use random sampling to estimate quantities that are hard to compute analytically. Estimating π: generate N random points (x,y) in the unit square [0,1]×[0,1]. Count points where x²+y²≤1 (inside the quarter circle). π ≈ 4 × (points inside) / N. With N=10,000 points, you typically get π accurate to about 2 decimal places. Monte Carlo methods are used in finance (option pricing), physics (particle simulation), and machine learning (probabilistic inference).

Statistical randomness testing verifies whether a sequence of numbers is truly random or contains hidden patterns. Common tests include: the chi-square test (checks if all values appear with expected frequency), the runs test (checks for alternating or repetitive patterns), the autocorrelation test (checks if a value predicts future values), and the frequency test (checks distribution of 0s and 1s in binary). The NIST test suite is the standard for cryptographic random number generators. True randomness is impossible to achieve with pure algorithms — computers use pseudo-random number generators (PRNGs) that are statistically random but deterministic. Hardware RNGs use physical entropy sources like thermal noise for true randomness.