How Random Number Generators Work

7 min read · Updated September 26, 2026 · by the SolveCalcPro editorial team

How Random Number Generators Work – feature image

Computers are deterministic machines, so “random” numbers need care. This guide explains how software produces random numbers, why some generators are better than others, and how our random number, random word and dice tools stay fair.

Pseudo-random versus truly random

A pseudo-random number generator (PRNG) starts from a seed and applies a formula that produces a sequence that looks random. The same seed gives the same sequence, which is great for simulations and games where repeatability helps, and terrible for security. A cryptographically secure generator is seeded with unpredictable entropy from the operating system — timings, hardware noise and other physical sources — so no one can predict the next value. Browsers expose it as crypto.getRandomValues().

Picking a whole number fairly

Turning raw random bits into a number from 1 to 6 sounds easy: take the bits and compute the remainder after dividing by 6. But if the bit range is not an exact multiple of 6, some outcomes become slightly more likely — “modulo bias”. The fix is rejection sampling: draw a number, throw it away if it falls in the leftover sliver at the top of the range, and draw again. Every result is then exactly equally likely. The random number generator and dice roller use this method.

Unique picks and shuffles

For lottery-style draws without repeats, there are two common approaches: keep drawing until you have enough different numbers, or shuffle the whole list and take the first few. The first is simple and efficient when the range is large; the second (the Fisher–Yates shuffle) is the right choice when you need many of the possibilities. The random word generator removes each word from the pool as it is chosen, which is the same idea.

What random does not mean

  • Even: True randomness produces streaks and clusters. Roll two six-sided dice many times and totals of 7 appear about one time in six, while 2 and 12 appear one time in 36 — yet short runs often look “wrong”.
  • Due: Past results do not change future odds. A die that rolled five 1s in a row is still fair.
  • Fair for money: For regulated lotteries and gambling, certified devices and audited processes are required; a web tool is for casual use.

Expected values are easy to check: 2d6 averages 2 / 7 / 12 (minimum / average / maximum).

Using random numbers well

Use random numbers for fair choices — raffles, team selection, sampling for a survey, practice problems — and for games. If you need a secret (a password, a token), use a generator designed for secrets such as the password generator, not a quick number picker.

Practice questions

Test yourself, then tap to check. Answers are calculated by the tools linked below.

  1. What is the chance of rolling two 4s with two fair dice?
    Show answer

    P(A and B), independent events: 0.027777778 · 2.77778% · 1/36

Frequently asked questions

Is Math.random() truly random?

No. It is a pseudo-random generator that is fast but predictable in principle, so it is not suitable for security. Cryptographic generators are preferable when fairness or secrecy matters.

What is modulo bias?

A small unfairness that appears when a range does not divide evenly into the generator’s output range. Rejection sampling removes it.

Can a random number generator be rigged?

A poorly designed one can be biased or predictable. Using the browser’s cryptographic source and rejection sampling avoids both problems.

Why do random numbers look streaky?

Because genuine randomness has no memory, so runs and clusters occur naturally.

Try it yourself

Keep learning

Written and reviewed by the SolveCalcPro editorial team. Spot a mistake? Tell us. See our editorial policy.