What is a random number generator?
A random number generator (RNG) produces numbers with no predictable pattern. There are two main types:
- True RNG (TRNG): Uses physical entropy — thermal noise, radioactive decay, atmospheric events. Found in hardware security modules and some OS-level APIs.
- Pseudorandom RNG (PRNG): Uses a deterministic algorithm seeded with an initial value. Outputs look random but are reproducible if the seed is known. Used in browsers, games, and simulations.
For everyday use — giveaways, games, picking a winner, statistical simulations — a high-quality PRNG like the browser's Math.random() is more than sufficient. It passes all standard randomness tests including Diehard and TestU01.
How to run a fair raffle — step by step
- Assign a number to each participant. If you have 50 people, your range is 1–50.
- Open the Random Number Generator. Select Raffle Draw mode.
- Set Min to 1 and Max to 50 (or whatever your participant count is).
- Set "How many" to the number of winners you need — e.g., 3 for first, second, and third prizes.
- Enable "No duplicates." This ensures each participant can only win once.
- Click Run Raffle Draw. Each ball animates independently and lands on a unique number.
- Copy and record the results. The History panel keeps the last 8 draws for reference.
The Fisher-Yates shuffle — how no-duplicate draws work
The Fisher-Yates shuffle (also called the Knuth shuffle) is the standard algorithm for producing uniformly random permutations:
- Create an array with every number in the range:
[1, 2, 3, …, N] - For each position from the last to the first, swap it with a randomly chosen earlier position.
- Take the first K elements of the shuffled array as your draw results.
Every permutation is equally likely, which makes it mathematically equivalent to drawing numbers from a physical urn — no bias, no duplicates.
Generate random numbers in code
JavaScript
// Random integer between min and max (inclusive)
function randInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
randInt(1, 100); // e.g. 42
// Cryptographically secure (for passwords/tokens)
const array = new Uint32Array(1);
crypto.getRandomValues(array);
const secure = array[0] % 100 + 1; // 1–100
Python
import random
# Single random integer
random.randint(1, 100) # e.g. 73
# Raffle: 5 unique numbers from 1–50
winners = random.sample(range(1, 51), 5)
# Cryptographically secure
import secrets
secrets.randbelow(100) + 1 # 1–100
Excel / Google Sheets
=RANDBETWEEN(1, 100) ' Random integer 1–100
=RANK(RAND(), RAND()...) ' Shuffle rows (workaround)
' Note: RANDBETWEEN recalculates on every change.
' Paste as values (Ctrl+Shift+V) to freeze results.
PHP
<?php
// Standard (Mersenne Twister)
$n = rand(1, 100);
// Cryptographically secure
$n = random_int(1, 100);
?>
Ruby
# Random integer 1–100
rand(1..100)
# Secure random
require 'securerandom'
SecureRandom.random_number(100) + 1
Tips for fair and transparent draws
- Record the draw live. Screen-share or stream while running the raffle to build trust.
- Use a fixed range. Announce the participant list and their assigned numbers before drawing.
- Enable no-duplicates whenever you need unique winners — never allow the same person to win twice in one draw.
- Screenshot the result and the history panel immediately after the draw for your records.
- Avoid re-rolling. Accept the first result unless there is a documented technical reason not to.
Frequently asked questions
Is Math.random() good enough for a raffle?
Yes. Browser PRNGs use algorithms like xorshift128+ that produce billions of distinct values with no detectable bias. For a raffle with hundreds or thousands of participants, the probability of any unfair outcome is negligible.
What's the difference between Math.random() and crypto.getRandomValues()?
Math.random() is fast and suitable for games, simulations, and draws. crypto.getRandomValues() uses the OS entropy pool and is cryptographically secure — required for passwords, tokens, and session IDs, but unnecessary overhead for simple number picking.
How do I generate a random number between 1 and 100?
Online: open our tool, set Min to 1 and Max to 100, click Generate. In code: Math.floor(Math.random() * 100) + 1 in JavaScript, or random.randint(1, 100) in Python.
Can two people get the same number in raffle mode?
Not when "no duplicates" is enabled. With duplicates allowed, the same number can appear more than once — useful when you're simulating dice rolls or sampling with replacement.
Conclusion
A good random number generator covers everything from picking tonight's dinner to running a fully auditable prize draw. For everyday use, browser-based PRNGs are statistically fair and more than sufficient. When you need cryptographic guarantees, reach for crypto.getRandomValues() or your language's secrets module.
Related tools
- UUID Generator — generate cryptographically unique identifiers
- Password Generator — create secure random passwords
- Percentage Calculator — calculate odds and probabilities