Metrics Calculator

Updated March 13, 2026

Random Number Generator

Generate random integers within any range, roll polyhedral dice (d4 through d20), or flip coins. Set the quantity, allow or disallow duplicates, and sort results. Uses pseudorandom generation suitable for games, sampling, and simulations.

Key Takeaways

  • Pseudorandom numbers (Math.random) are suitable for games, simulations, sampling, and classroom exercises, but not for cryptography.
  • The Fisher-Yates shuffle ensures truly uniform random selection when duplicates are disallowed.
  • For 2d6, the most probable sum is 7 (probability 1/6 ≈ 16.7%), while 2 and 12 each have probability 1/36 ≈ 2.8%.
  • A fair coin has exactly 50% probability for each side. Over many flips, the ratio converges to 50/50 (law of large numbers).
  • Generate up to 1,000 numbers at once with optional sorting and duplicate control.

How Random Number Generation Works

A random number generator (RNG) produces a sequence of numbers that lack any predictable pattern. Computer-based RNGs use mathematical algorithms that take a starting value (seed) and produce a deterministic sequence that appears random. These are called pseudorandom number generators (PRNGs).

To generate a random integer between a minimum and maximum value, the formula is:

Random Integer = floor(random() × (max − min + 1)) + min

random() produces a value from 0 (inclusive) to 1 (exclusive). Multiplying by the range size and flooring gives a uniform integer distribution.

Coach Rivera uses the random number generator to assign drill partners at Pinewood Falls High. With 24 players on the roster, he generates numbers 1-24 without duplicates, then pairs them off sequentially. The first two numbers form pair 1, the next two form pair 2, and so on. This eliminates any bias in partner selection and keeps practice competitive.

Pseudorandom vs. True Random

There is an important distinction between pseudorandom and true random number generators. Understanding when each is appropriate prevents misuse.

Feature Pseudorandom (PRNG) True Random (TRNG)
SourceMathematical algorithmPhysical phenomenon (atmospheric noise, radioactive decay)
DeterministicYes (same seed = same sequence)No
SpeedVery fastSlower (depends on entropy source)
Use casesGames, simulations, sampling, statisticsCryptography, lotteries, security keys
ExampleMath.random(), Mersenne Twisterrandom.org, hardware RNG chips

For passwords and encryption, use the Web Crypto API (crypto.getRandomValues) which accesses the operating system's cryptographic RNG. Our password generator uses this approach.

Dice Probability Reference

When rolling multiple dice, the probability of each sum depends on how many combinations produce that total. The table below shows the probability distribution for 2d6 (two six-sided dice), the most common dice roll in board games.

Sum Combinations Probability Sum Combinations Probability
212.78%8513.89%
325.56%9411.11%
438.33%1038.33%
5411.11%1125.56%
6513.89%1212.78%
7616.67%

Total possible outcomes for 2d6 = 6 × 6 = 36. The sum of 7 has the most combinations (1+6, 2+5, 3+4, 4+3, 5+2, 6+1).

For a single die with n sides, each face has a probability of exactly 1/n. The expected value (average roll) is (n + 1) / 2. For a d6, that's 3.5. For a d20, it's 10.5.

Common Uses for Random Numbers

Random number generation has applications across many fields. The table below shows common use cases and the appropriate generator type for each.

Use Case Range / Type Generator
Lottery numbers (Powerball)5 numbers from 1-69 + 1 from 1-26True RNG (official); PRNG (for fun)
Raffle drawing1-N (no duplicates)PRNG is fine
Board game diced6, 2d6PRNG is fine
D&D ability scores4d6 drop lowest, ×6PRNG is fine
Statistical samplingRow numbers from datasetPRNG is fine
A/B test assignment0 or 1 (50/50)PRNG is fine
Password generationCharacters from setCryptographic RNG required
Encryption keysLarge integersCryptographic RNG required

PRNG = pseudorandom number generator (this tool). Cryptographic RNG = crypto.getRandomValues() or hardware entropy source.

Tom, Pinewood Falls' retired engineer, uses the random number generator to pick which house projects to tackle each weekend. He numbers his project list 1 through 12 and lets the generator decide. "Takes the decision fatigue out of it," he says. He uses the percentage calculator to track what fraction of his project list he has completed.

The Law of Large Numbers

The law of large numbers states that as the number of trials increases, the average of the results approaches the expected value. For a fair coin, the proportion of heads approaches 50% as you flip more and more times. However, this does not mean that short-term deviations are "corrected." It means they become proportionally insignificant.

After 10 flips, getting 7 heads (70%) is common. After 1,000 flips, getting 700 heads (70%) is extremely unlikely. The absolute deviation might grow (say, 520 heads vs. 500 expected), but the percentage deviation shrinks (52% vs. 50%). This is why casinos are profitable: the longer you play, the more closely the results match the house edge.

Maya uses the coin flip tool to settle disputes with her study group at Pinewood Falls High. She once flipped 100 coins to demonstrate the law of large numbers for a statistics project. The result was 47 heads and 53 tails, close to the expected 50/50 split. Her teacher, impressed, suggested she use the test grade calculator to see what score she needed on the final to keep her A.

This generator uses JavaScript's Math.random() pseudorandom number generator. It is suitable for games, educational exercises, casual sampling, and entertainment. Do not use it for cryptographic purposes, official lottery drawings, or security-critical applications.


Related Calculators

Frequently Asked Questions

Are these random numbers truly random?

This generator uses Math.random(), which produces pseudorandom numbers, which are numbers generated by an algorithm that appear random but are deterministic. For most purposes (games, sampling, simulations, classroom exercises), pseudorandom numbers are perfectly adequate. For cryptographic applications (passwords, encryption keys), use a cryptographically secure generator like the Web Crypto API instead.

How do I generate random numbers without duplicates?

Uncheck the "Allow duplicates" option. The generator uses the Fisher-Yates shuffle algorithm to select unique numbers from the range. Note: the quantity cannot exceed the range size. For example, you cannot generate 20 unique numbers from the range 1-10.

What is the maximum number I can generate?

The generator supports any integer range within JavaScript's safe integer limit (up to 9,007,199,254,740,991). You can generate up to 1,000 numbers at once. For most practical uses (lotteries, random sampling, game mechanics), these limits are more than sufficient.

How does a dice roller work?

A dice roller generates a random integer between 1 and the number of sides on the die. A standard six-sided die (d6) produces values 1 through 6 with equal probability (1/6 each). For multiple dice, each die is rolled independently. The total of 2d6 ranges from 2 to 12, with 7 being the most probable sum.

What does d4, d6, d8, d10, d12, d20 mean?

The "d" stands for "die" (singular of dice). The number after it indicates how many sides the die has. d6 is a standard six-sided die. d20 is a twenty-sided die commonly used in tabletop role-playing games like Dungeons & Dragons. d4, d8, d10, and d12 are other polyhedral dice used in various game systems.

Is a coin flip truly 50/50?

A simulated coin flip using a fair random number generator is exactly 50/50. In real life, studies have shown physical coin flips have a slight bias (~51/49) toward the side facing up at the start of the flip, due to the physics of rotation. For practical purposes, both simulated and physical coin flips are considered fair.

How often do people use random number generators?

Random number generators are used frequently in tabletop gaming (every session), statistical research (during data collection and sampling), classroom exercises (daily for teachers assigning groups), raffle drawings (at events), and A/B testing (continuously during experiments). The frequency depends entirely on the application.