๐ŸŽฒ

Random Number Generator

Generate random integers, decimals, coin flips, dice rolls, or shuffle a list using cryptographic randomness.

MATH

Generate random integers, decimals, coin flips, dice rolls, or shuffle a list using cryptographically secure randomness.

Six modes: integer range, decimal range, list shuffle, coin flip (with optional weighted coin), dice roller (d4 to d100 plus custom), and random pick. Uses Web Crypto with rejection sampling to avoid modulo bias.

Disclaimer: Suitable for everyday randomness needs. For cryptographic key generation, use a vetted library. For sweepstakes and official giveaways, verify the underlying randomness with an auditor.
Loading calculatorโ€ฆ
Advertisement

Calculator information

How to use this calculator

  1. Pick a mode: Integer Range, Decimal Range, List Shuffle, Coin Flip, Dice Roller, or Random Pick.
  2. For Integer/Decimal Range, enter the lower and upper bounds (inclusive for integers). Example: 1 to 100.
  3. Specify how many numbers to generate (1-1000) and toggle 'unique, no duplicates' if needed.
  4. For the Dice Roller, choose a die type (d4, d6, d8, d10, d12, d20, d100) or build a custom roll (e.g., 3d6 + 2).
  5. Click Generate. Results can be copied to the clipboard or regenerated without losing your settings.
  6. Tip: for prize drawings, save a screenshot of the result as evidence; randomness comes from the browser's Web Crypto API, not Math.random().

Cryptographic Random with Rejection Sampling

raw = crypto.getRandomValues(Uint32Array) ; threshold = floor(2^32 / range) * range ; if raw < threshold: result = min + (raw mod range)
  • range = max - min + 1 (for inclusive integers)
  • raw = 32-bit unsigned random integer from the CSPRNG
  • threshold = largest multiple of range less than 2^32, used to avoid modulo bias
  • If raw >= threshold, draw a new sample (rejection sampling)

The Web Crypto API relies on an OS-level CSPRNG (getrandom on Linux, BCryptGenRandom on Windows). Plain modulo without rejection sampling introduces bias when 2^32 is not evenly divisible by range.

Worked example: Generate 5 unique numbers from 1 to 49 for a raffle or A/B test

Given:
  • Mode: Integer Range
  • Min: 1, Max: 49
  • Count: 5, Unique: Yes
Steps:
  1. range = 49 - 1 + 1 = 49.
  2. threshold = floor(4294967296 / 49) * 49 = 87652393 * 49 = 4294967257.
  3. Draw the first raw value, say 1234567890; since 1234567890 < 4294967257, it is accepted.
  4. result = 1 + (1234567890 mod 49) = 1 + 17 = 18.
  5. Repeat until 5 distinct numbers are produced; duplicates are discarded and a new sample is drawn.

Result: Sample output: 7, 18, 23, 31, 42.

Frequently asked questions

What is the difference between Math.random() and Web Crypto?
Math.random() uses a PRNG (xorshift or Mersenne Twister) that is deterministic from an internal seed and is not suitable for security or audit-grade use. Web Crypto (crypto.getRandomValues) uses an OS-level CSPRNG, passes NIST SP 800-22 statistical tests, and is safe for raffles, drawings, or secret tokens. This calculator uses Web Crypto exclusively.
Why is rejection sampling necessary?
A direct modulo operation (raw mod range) gives different probabilities to each value when 2^32 is not evenly divisible by range. For example, with range 7 the values 0-5 appear slightly more often than 6. Rejection sampling discards samples in the uneven zone so the resulting distribution is truly uniform.
Will I get the same result if I refresh the page?
No. Every generation pulls fresh bytes from the OS CSPRNG, whose state is constantly changing, so reproducing the exact same result is effectively impossible. There is no seed you can set for reproducibility; if you need reproducibility, save the output.
Can this be used for an official prize drawing?
Mathematically the randomness is sound, but in the United States official sweepstakes and prize promotions are regulated state-by-state (most stringently in Florida, New York, and Rhode Island, which require bonding and registration). The output of this generator can serve as documentation only - not a substitute for the required legal procedures, registration, and independent witnessing.
What is the maximum number of values per generation?
The calculator caps each call at 1,000 numbers to keep the UI responsive. For larger datasets, run multiple generations or use a library outside the browser. The integer range is supported up to Number.MAX_SAFE_INTEGER (2^53 - 1).

Last updated: May 11, 2026

Sponsored