ウィキ

Random Number Generation and Uniform Distribution

How random numbers are generated, uniform distribution properties, and permutations without replacement. Formulas and practical applications.

Verified against NIST SP 800-90A - Recommendation for Random Number Generation on 20 Feb 2025 Updated 20 February 2025 4 min read
計算ツールを開く

Translation unavailable - this article is shown in English. View English version

Summary

A random number generator (RNG) produces numbers that cannot be predicted better than by chance. In computing, most RNGs are pseudorandom — they use deterministic algorithms seeded with an initial value to produce sequences that appear random but are reproducible. True random number generators derive entropy from physical processes (thermal noise, radioactive decay). This calculator generates random integers within a specified range using a uniform distribution, where every value in the range is equally likely.

How it works

The calculator supports several modes:

  1. Single random number — generates one integer between a minimum and maximum value (inclusive), drawn from a discrete uniform distribution.
  2. Multiple random numbers — generates a set of random integers. Values may repeat (sampling with replacement) unless uniqueness is specified.
  3. No repeats (permutation) — draws values without replacement. The number of possible orderings of k items chosen from n is given by the permutation formula.

Pseudorandom vs true random

Browsers use crypto.getRandomValues(), a cryptographically secure pseudorandom number generator (CSPRNG) that meets NIST SP 800-90A standards. This is suitable for games, simulations, and general-purpose randomization. For cryptographic key generation or gambling regulation, hardware-based true RNGs are required.

The formulas

P(X = x) = 1 / (b - a + 1) for a <= x <= b

Where

P(X = x)= Probability of any specific outcome
a= Minimum value (inclusive)
b= Maximum value (inclusive)
Permutations without replacement: P(n, k) = n! / (n - k)!

Where

n= Total number of possible values in the range
k= Number of values to draw
n!= n factorial (n * (n-1) * ... * 1)

Worked examples

Probability of rolling a specific number on a die

1

Identify the range

a = 1, b = 6

= 6 possible outcomes

2

Apply uniform distribution formula

P(X = 4) = 1 / (6 - 1 + 1) = 1/6

= 0.1667 (16.67%)

Result

Each face has a 1 in 6 (16.67%) chance

How many ways to draw 3 unique numbers from 1-10?

1

Identify n and k

n = 10, k = 3

= n = 10, k = 3

2

Apply permutation formula

P(10, 3) = 10! / (10-3)! = 10! / 7! = 10 * 9 * 8

= 720

Result

There are 720 possible ordered selections of 3 unique numbers from 1 to 10

Practical uses

  • Games and lotteries — dice rolls, card shuffles, raffle drawings, and lottery number selection all rely on uniform random generation.
  • Statistical sampling — researchers randomly select participants from a population to avoid selection bias.
  • Simulations — Monte Carlo methods use random numbers to model complex systems in finance, physics, and engineering.
  • Randomized algorithms — many computer science algorithms (quicksort pivot selection, hash functions) use randomness for efficiency.

Assumptions & limitations

  • Pseudorandom, not truly random — browser-generated numbers are computationally unpredictable but ultimately deterministic. For most purposes this is sufficient.
  • Integer range — this calculator generates integers only. For continuous random values, the result can be divided by a power of 10.
  • No-repeat constraint — when generating unique values, the count requested cannot exceed the range size. Requesting 20 unique numbers from 1-10 is impossible.
  • Uniform only — this calculator produces a uniform distribution. Other distributions (normal, exponential) require transformation methods.

出典

random-number uniform-distribution rng probability math