Random Number Generator

Generate truly random numbers in any range. Single or bulk generation, unique numbers, sorting, and a full dice roller (d4 to d100). Uses Web Crypto API.

set range and generate
Min
Max
How many
Result (click to copy)
Dice roller
History (last 20 single rolls — click to copy)

How to Use the Random Number Generator

  1. Set the minimum value — the lowest possible number in your range (e.g. 1).
  2. Set the maximum value — the highest possible number in your range (e.g. 100).
  3. Choose count — generate one number or multiple numbers at once.
  4. Select uniqueness — toggle 'no duplicates' to ensure each generated number appears only once (useful for lottery draws, random sampling).
  5. Generate and copy — click generate for instant random numbers. Click again for a new set.
🎲 True randomness note: This generator uses JavaScript's crypto.getRandomValues() — a cryptographically secure random number generator (CSPRNG). This provides true unpredictability suitable for security applications, unlike Math.random() which uses a pseudo-random algorithm that is predictable if the seed is known.

Understanding Randomness in Computing

🎲 True vs Pseudo-Random
True random numbers come from physical phenomena (atmospheric noise, radioactive decay). Pseudo-random numbers are generated by deterministic algorithms from a seed value — same seed always produces the same sequence. Pseudo-random is sufficient for simulations; true random or CSPRNG is required for security applications.
🔐 CSPRNG vs Math.random()
JavaScript's Math.random() uses a pseudo-random algorithm — not suitable for security. crypto.getRandomValues() uses the OS's CSPRNG — suitable for security. The difference: Math.random() output could theoretically be predicted if the algorithm state is known. CSPRNG output cannot be predicted even with full knowledge of past outputs.
📊 Uniform Distribution
A good random number generator produces a uniform distribution — every number in the range has an equal probability of being selected. Over many generations, you should see roughly equal frequency for each possible value. Checking distribution is one way to verify random number quality.
🔢 Range and Bias
Converting from a random byte to a specific range requires care to avoid modulo bias. If you want 1–6 (dice roll) from a 0–255 random byte: 256 / 6 = 42.67, not a whole number. Simple modulo operation (byte % 6) slightly over-represents numbers 0–1. Correct approach: rejection sampling — discard values above 251 and try again.
🌐 Applications
Lotteries and prize draws. Statistical sampling. Game dice and card shuffling. Password salt generation. Session ID generation. A/B test group assignment. Monte Carlo simulations. Music playlist shuffling. Quiz question ordering. Load balancer distribution.
📈 Seed-Based Reproducibility
Sometimes you need randomness that is reproducible — same random sequence when needed for debugging. Seeded pseudo-random generators (like Mersenne Twister) enable this: set a specific seed, get a consistent sequence. Useful in game development, scientific simulations, and debugging random-dependent code.

Random Numbers in Development

Cryptographically secure random numbers

For any security-sensitive use — password salts, session tokens, CSRF tokens, encryption keys — always use a CSPRNG. In Node.js: crypto.randomBytes(32). In Python: secrets.token_bytes(32) or os.urandom(32). In Java: SecureRandom. In Go: crypto/rand. Never use language-default random functions (Math.random(), random.random()) for security-sensitive values — they are predictable by design.

Random sampling techniques

Fisher-Yates shuffle is the correct algorithm for random array shuffling: iterate from last element to first, swap each element with a randomly chosen element from the remaining unshuffled portion. Naive approaches (sort by random value) produce biased results. For selecting k items from n without replacement: shuffle the array, take first k elements. For weighted random selection: generate random number and use cumulative weights to find the selected item.

A/B testing and experiment assignment

Random assignment to test groups must be: uniform (each group has equal probability), deterministic for a given user (same user always in same group across sessions), and independent of other random assignments. Common approach: hash(user_id + experiment_id) % 100 < target_percentage. This produces consistent group assignment without storing it explicitly, using modular arithmetic on a hash for uniform distribution.

🎲 Random number quick reference: Dice roll (1-6): Math.floor(Math.random() * 6) + 1. Coin flip: Math.random() < 0.5. Random array element: arr[Math.floor(Math.random() * arr.length)]. Random float (0-1): Math.random(). Secure random bytes: crypto.getRandomValues(new Uint8Array(32)). UUID v4: crypto.randomUUID(). These cover 95% of random number needs in JavaScript.

Frequently Asked Questions

Is this truly random?
Yes. This tool uses crypto.getRandomValues() — the Web Cryptography API — which is cryptographically secure randomness. Unlike Math.random(), which uses a deterministic algorithm, crypto.getRandomValues() uses entropy from your operating system's secure random source.
What does 'unique numbers only' mean?
When enabled, no number will appear twice in the generated list. For example, generating 6 unique numbers between 1 and 6 is equivalent to rolling a standard die 6 times with no repeats — like a lottery draw. The range must be large enough to accommodate the count.
What are the dice options (d4, d6, d20)?
These are standard tabletop RPG dice. d6 is a standard 6-sided die, d20 is a 20-sided die used in Dungeons & Dragons, and d100 (percentile die) generates 1–100. All use the same cryptographic randomness as the main generator.
Can I generate lottery numbers?
Yes. Set min to 1, max to 49 (or your lottery's max), count to 6 (or however many numbers), and enable 'unique numbers only'. Click Generate. Each number in the range has an equal probability of being selected.