fileformer
search⌘KtranslateENexpand_moreupload_fileConvert
Converters8 file families · 44 direct conversions
What changes in a conversionarrow_forward
home/random-tools/random-number

Free Random Number Generator Online

Random number generator

Pick fair numbers for raffles, games, sampling or decisions: using your browser's cryptographic randomness, not a predictable formula.

pinNumbercasinoDicetollCoinconfirmation_numberLottery
No repeatseach number appears onceSort resultslowest to highest
Quick ranges
1-101-1001-10000-91-61-20
casinoGenerate
1 number between 1 and 100, no repeatsroll #1
42
history-
content_copyCopy
~/how-random-is-it

Fair by design.

Most "random" functions follow a formula that can be predicted. This tool uses the same source of randomness browsers use for encryption keys.

lockCryptographically secureNumbers come from crypto.getRandomValues, the source browsers use for encryption keys, not Math.random().
balanceNo biasOut-of-range values are rejected and redrawn, so every number in your range is exactly as likely as the others.
visibility_offNothing recordedResults are generated on your device and never sent anywhere, so no one can replay or predict them.
~/prove-it

Roll it a thousand times.

A fair die lands on each face about equally often, but never perfectly evenly in small runs. Run the test and watch the bars settle as the rolls add up.

+60 rolls+1,000Reset
0
0
0
0
0
0
⚀⚁⚂⚃⚄⚅
expected if perfectly even
total rolls0
expected per face-
biggest deviation-
Press “+60 rolls” to start. With few rolls, expect big differences, that’s normal randomness, not bias.
~/where-randomness-comes-from

Not all “random” is equal.

Computers are predictable machines, so producing unpredictable numbers takes care. There are three common approaches.

functionsused here
Pseudo-randomMath.random()A formula that produces a long, random-looking sequence from a starting seed. Fast, but if someone learns the seed they can predict every number.Good for:games, animations, simulations.
lockused here
Cryptographiccrypto.getRandomValues()The operating system mixes unpredictable events, hardware timing, input, sensor noise, into a secure generator. It can’t be predicted from past output.Good for:draws, winners, passwords and keys.
blur_onused here
Physicaldice · atomic noiseMeasures a physical process such as radioactive decay or atmospheric noise. Truly unpredictable, but needs special hardware.Good for:official lotteries and scientific research.
~/ready-made-settings

Six common jobs, set up in one click.

redeemRaffle winner
Number your entries 1 to N and draw one. Share the roll number for transparency.number · 1-250 · ×1Use these settingsnorth_east
emoji_eventsTop 3 prizes
Draw three different winners in order: first, second and third place.number · 1-500 · ×3 · no repeatsUse these settingsnorth_east
scienceSurvey sample
Pick 20 respondents from a list of 1,000 without picking anyone twice.number · 1-1000 · ×20 · sortedUse these settingsnorth_east
groupsSplit into teams
Give 12 players a number each, draw 6, they’re team A, the rest team B.number · 1-12 · ×6 · sortedUse these settingsnorth_east
casinoBoard game night
Roll two six-sided dice at once, with the total shown.dice · ×2Use these settingsnorth_east
tollSettle a decision
One fair coin flip: heads you go, tails you stay.coin · ×1Use these settingsnorth_east
~/why-a-formula-is-not-enough

Two outputs are enough to predict the rest.

A pseudo-random generator is a formula applied to a hidden state. If its outputs reveal enough of that state, an observer can rebuild it and predict every later number. The attack below runs live in your browser against Java’s java.util.Random. The panel beside it shows a second kind of failure: outputs that look random one at a time but follow a pattern together.

Recovering a 48-bit LCGrefreshNew hidden seed
State update: s = (s × 0x5DEECE66D + 0xB) mod 2⁴⁸. Each nextInt() returns the top 32 bits of s, so one output leaves only 16 bits unknown. The attack tries all 65,536 possibilities and keeps those that also produce the second output.
nextInt() #1 (observed)1,075,614,125
nextInt() #2 (observed)1,439,206,317
candidates tried65,536
matching states1
time11.8 ms
recovered state0x401C91AD2DDD
outputpredictedactual
#34,185,501,4084,185,501,408check_circle
#4154,918,526154,918,526check_circle
#53,609,329,9893,609,329,989check_circle
#6838,751,051838,751,051check_circle
#73,943,344,8413,943,344,841check_circle
#83,551,590,6083,551,590,608check_circle
#959,735,89959,735,899check_circle
#10815,411,263815,411,263check_circle
gpp_badAll 8 later outputs predicted exactly. The true state after output 1 was 0x401C91AD2DDD.
Browsers’ Math.random() uses xorshift128+ rather than an LCG, but it is not safer for this purpose: published attacks rebuild its 128-bit state from a few consecutive outputs with an SMT solver. crypto.getRandomValues() is designed so that no number of outputs reveals its state.
RANDU: random alone, ordered in threesIBM’s 1960s generator multiplied by 65,539 mod 2³¹. Because 65,539 = 2¹⁶ + 3, every output satisfies xₖ₊₂ = 6xₖ₊₁ − 9xₖ (mod 1). Below, 3,000 consecutive triples are combined as 9x − 6y + z. A good source spreads that value smoothly; RANDU can only ever hit whole numbers.
RANDU, seed 115 distinct values
crypto.getRandomValues3,000 distinct values
-6-5-4-3-2-10123456789
Plotted in 3D, RANDU’s triples fall on 15 parallel planes. George Marsaglia showed in 1968 that every multiplicative LCG has this lattice structure; RANDU’s happens to be extreme. Simulations that used it, including published physics results, inherited the pattern.
~/shuffling-fairly

A fair random source can still give an unfair shuffle.

Shuffling a list is the usual next step after picking random numbers: drawing an order of play, assigning seats, randomising a survey. Three common methods are run below on the same list, many times each, and every possible order is counted. Only one of them makes every order equally likely.

3 items4 items
shuffleRun again
Fisher: Yates (Durstenfeld)for i from n−1 down to 1: j = random(0..i) swap a[i], a[j]
χ² (df 23)20.4
p-value0.6181
most / least1.08×
most common2413
check_circleConsistent with a fair shufflen! equally likely swap paths, one per order. This is the algorithm to use.
123412431324134214231432213421432314234124132431312431423214324134123421412341324213423143124321
Naive swapfor i from 0 to n−1: j = random(0..n−1) swap a[i], a[j]
χ² (df 23)2113.5
p-value< 0.000001
most / least1.89×
most common2143
errorBiased: orders are not equally likely4^4 = 256 equally likely swap paths spread over 24 orders. 256 is not divisible by 24, so some orders must come up more often.
123412431324134214231432213421432314234124132431312431423214324134123421412341324213423143124321
Sort with a random comparatora.sort(() => Math.random() − 0.5)
χ² (df 23)40018.9
p-value< 0.000001
most / least8.59×
most common2134
errorBiased: orders are not equally likelyThe result depends on the browser’s sort algorithm, which assumes a consistent comparison. V8 uses TimSort, so short arrays get insertion-sort behaviour and elements tend to stay near where they started.
123412431324134214231432213421432314234124132431312431423214324134123421412341324213423143124321
expected count if every order were equally likely72,000 shuffles per method, 216,000 in total, run in 41 ms. Fisher: Yates and naive swap draw from crypto.getRandomValues.
~/when-to-switch-on-no-repeats

Repeats turn up far sooner than intuition says.

Drawing k numbers from a range of n with repeats allowed, the chance that two match grows with k², not k. This is the birthday problem: 23 people give better-than-even odds of a shared birthday. The exact probability is computed below, then checked by actually drawing with your browser’s secure generator.

Your settingsBirthdays4-digit PINsRaffleLotto tickets
casinoSimulate with real draws5,000 trials of 23 draws took 9 ms. Expect the measured figure to wander by about ±1.4 points.
exact chance of at least one repeat50.7%
measured in 5,000 trials51.2%
expected matching pairs0.693k(k−1) / 2n
draws for a 50% chance23≈ 1.18 × √n
with “No repeats” on24 drawsaverage draws to collect k unique values
k as share of n6.30%repeats are likely well before this is large
P(no repeat) = (n−1)/n × (n−2)/n × … × (n−k+1)/n ≈ e^(−k(k−1) / 2n)
~/reference

Generators in use, and the browser’s rules.

Period is how long a generator runs before repeating; state is how much hidden memory it has. Neither makes a generator secure. That depends on whether outputs reveal the state.

generatormethodperiodstateused bysecure?
RANDULCG ×65539 mod 2³¹2²⁹4 BIBM System/360 scientific libraries, 1960scancelno: triples lie on 15 planes
java.util.Random48-bit LCG2⁴⁸6 BJava and its many portscancelno: 2 outputs reveal the state
Mersenne Twister (MT19937)twisted GFSR2¹⁹⁹³⁷ − 12.5 KBPython random, PHP mt_rand, Ruby, Rcancelno: 624 outputs reveal the state
xorshift128+xor-shift plus add2¹²⁸ − 116 BMath.random() in V8, SpiderMonkey and JavaScriptCorecancelno: solvable from a few outputs
PCG64LCG with output permutation2¹²⁸32 BNumPy default since 1.17 (2019)cancelno: not designed for it
ChaCha20 CSPRNGstream cipher, reseededreseeded~64 BLinux getrandom and /dev/urandom (4.8+), OpenBSD arc4randomverified_useryes
CTR_DRBG (AES)NIST SP 800-90A block cipherreseeded48 BWindows BCryptGenRandomverified_useryes
Dual_EC_DRBGelliptic-curve pointsreseeded-RSA BSAFE default until 2013dangerouswithdrawn: suspected backdoor

Browser randomness APIs, tested here

The last column is the result of running each call in this tab.
callrulethis browser
crypto.getRandomValues(new Uint8Array(65536))Maximum 65,536 bytes per call.ok, 65,536 bytes
crypto.getRandomValues(new Uint8Array(65537))One byte over the limit throws QuotaExceededError.throws QuotaExceededError
crypto.getRandomValues(new Float64Array(4))Integer typed arrays only. Floats throw TypeMismatchError.throws TypeMismatchError
crypto.randomUUID()Version 4 UUID from the same source. Secure contexts only.519430cf-a48b-494f-94a6-d9606c38fe91
window.isSecureContextrandomUUID and crypto.subtle need HTTPS or localhost; getRandomValues does not.true
Math.random() step sizeThe spec asks only for approximately uniform values in [0, 1). Engines choose the resolution.2^−53 (53 random bits)

Timeline

1938Fisher and Yates publish a pencil-and-paper shuffle in their Statistical Tables.
1946John von Neumann proposes the middle-square method.
1949D. H. Lehmer describes the linear congruential generator.
1955RAND publishes A Million Random Digits with 100,000 Normal Deviates.
1964Durstenfeld publishes the in-place computer shuffle (CACM Algorithm 235).
1968Marsaglia shows that LCG outputs fall mainly in the planes.
1998Matsumoto and Nishimura publish the Mersenne Twister.
2003Marsaglia introduces xorshift generators.
May 2008Debian discloses that since 2006 its OpenSSL could generate only about 32,767 keys of each type.
2014NIST drops Dual_EC_DRBG from its draft SP 800-90A; Linux 3.17 adds getrandom().
Dec 2015V8 4.9 switches Math.random() to xorshift128+ (shipped in Chrome 49).
2016Linux 4.8 rebuilds /dev/urandom on ChaCha20.