CALCULATORCASTLE

Random Number Generator

Generate random numbers within any range with customizable options.

About

Random Number Generator

Two generators sit above this. The first returns a single random whole number between your limits and copes with values thousands of digits long. The second produces one number or many, as integers or decimals, at whatever precision you ask for. Both show how the number was actually arrived at rather than simply presenting it.

What a random number is

A random number is one drawn from a set with no pattern that would let you predict it. Two properties matter and they are separate. Independence means each draw tells you nothing about the next, so a coin that has landed heads nine times is still an even bet on the tenth. Uniformity means every value in the range is equally likely.

Not every random quantity is uniform. The heights of students in a school cluster around the middle and thin out at both ends, so a randomly chosen student is more likely to be near the average than very tall. That is a normal distribution rather than a flat one. The generators above are uniform by design: every value between your limits carries the same chance, which is what you want for a lottery pick or a simulation and not what you want if you are modelling heights.

How a computer produces one

Random number generators fall into two families. Hardware generators read something physically unpredictable: a rolled die, a flipped coin, thermal noise in a resistor, the timing of radioactive decay, or the path of a photon through a beam splitter. Pseudo-random generators are algorithms. They start from a seed and produce a sequence that passes statistical tests for randomness while being entirely determined by that seed.

Almost everything on a computer is the second kind, including the generators on this page, and the label matters: run the same algorithm from the same seed and you get the same sequence every time. That reproducibility is a feature in simulation work, where a run has to be repeatable, and a serious liability anywhere secrecy is involved.

John von Neumann, who devised one of the first such algorithms, put it plainly in 1951: anyone who considers arithmetical methods of producing random digits is, of course, in a state of sin. He was making a real point. An algorithm cannot manufacture unpredictability, only stretch whatever it was given.

Where the randomness on this page comes from

These generators do not use the ordinary Math.random found in most web calculators. That function carries no guarantee of quality in the JavaScript specification, cannot be seeded, and is explicitly not safe to rely on where predictions would matter.

Instead they draw bytes from the browser's cryptographic generator, which is seeded from operating system entropy and is designed so that seeing part of the output tells an observer nothing useful about the rest. It is the same source a browser uses when generating key material.

The second detail is how those bytes become a number in your range. The tempting method is to take a big random number and use the remainder after dividing by the range size. That introduces modulo bias: unless the range divides the byte space evenly, the low end of the range picks up slightly more of the possibilities than the high end. On small ranges the effect is invisible; on large ones it is real and measurable.

value=lower+drawwhere draw is uniform in[0,upperlower+1)

These generators avoid it by rejection. A draw that lands outside the range is thrown away and a fresh one taken, so every value keeps exactly the same chance. It costs a few extra draws occasionally and buys genuine uniformity.

Decimals and large numbers

Decimals are handled by scaling rather than by multiplying a fraction, which is where most implementations lose accuracy. Ask for ten decimal places between 0.2 and 112.5 and the range becomes the whole numbers from 2,000,000,000 to 1,125,000,000,000, which is 1,123,000,000,001 possible values. One is drawn uniformly and the decimal point is put back:

value=scaled lower+draw10p

Because the arithmetic runs in exact integers throughout, every value at your chosen precision is equally likely and none of the usual floating-point drift creeps in. The same machinery is what lets the first generator handle limits thousands of digits long, well past the roughly sixteen digits an ordinary decimal number can hold exactly.

True randomness

Where prediction genuinely must be impossible, the seed has to come from the physical world. Random.org has sampled atmospheric radio noise since 1998. Cloudflare famously points a camera at a wall of lava lamps in its San Francisco lobby and folds the image into its entropy pool. Modern Intel and AMD processors include an on-die noise source reachable through the RDRAND instruction, and quantum generators use the genuinely indeterminate behaviour of single photons.

All of them need care afterwards. A physical source is rarely perfectly balanced, so the raw output is corrected for bias before use, typically by mixing it through a hash function.

How anyone checks a generator is worth knowing. Statistical batteries such as the NIST SP 800-22 suite and TestU01 run a sequence through dozens of tests looking for structure: too few long runs, correlations at particular lags, frequencies drifting from expectation. Passing them proves nothing about security, only that no obvious pattern shows up.

What random numbers get used for

Simulation. Monte Carlo methods answer questions too tangled for algebra by running them thousands of times with random inputs. The technique was developed at Los Alamos in the 1940s by Stanislaw Ulam and von Neumann, and named after the casino.

Cryptography. Keys, nonces and salts must be unguessable. This is the one job that needs a cryptographic generator rather than a statistical one.

Sampling. Picking survey respondents or audit records at random is what makes a sample representative and stops selection creeping in.

Games and allocation. Dice, shuffles, loot drops, prize draws and randomised A/B test assignment.

The cost of getting it wrong is not theoretical. A change to Debian's OpenSSL package between 2006 and 2008 crippled the entropy going into key generation, leaving every key produced on those systems drawn from a set small enough to enumerate. Thousands of keys had to be replaced. The algorithm was fine; the randomness feeding it was not.

Reading your result

Both generators include their limits, so a range of 1 to 100 can return 1 or 100 and there are 100 possible outcomes rather than 99.

Press Generate for a fresh draw. Repeats are not a fault: across a range of 100, two draws in a row matching has a 1 in 100 chance, and over enough draws a repeat is close to certain rather than suspicious. Expecting randomness to avoid repetition is the same instinct that makes a genuinely random playlist feel broken.

These numbers are suitable for simulations, sampling, games and picking winners. For anything protecting real value, generate the material inside the system that will use it rather than copying a number off a web page, wherever it came from.

Modulo bias, and why this page avoids it

The obvious way to turn a random byte into a die roll is to take the remainder after dividing by six. It is also wrong. A byte holds 256 values, and 256 does not divide by 6. Working through them, four of the faces come up 43 times and two come up 42, so a die built this way is measurably loaded toward the low faces.

The fix is rejection sampling. Discard any value that falls in the uneven tail, in this case the last four of the 256, and draw again. The remaining 252 values split evenly into six groups of 42. It costs an occasional extra draw and produces a genuinely uniform result, which is what this generator does for every range you ask for.

Two different generators, for two different jobs

The generator behind a language's ordinary random function is built for speed and statistical quality, not secrecy. Mersenne Twister, long the default in Python and elsewhere, repeats only after 2^19937 - 1 numbers, yet its internal state can be reconstructed from a few hundred outputs, after which every future number is predictable. JavaScript's Math.random carries the same warning and is explicitly not suitable for anything security related.

This page uses the browser's cryptographic generator instead, reached through crypto.getRandomValues, which is seeded from operating system entropy and designed so that past output reveals nothing about what comes next. It fills at most 65,536 bytes per call and throws a quota error beyond that, so a long list of numbers is drawn in batches. The practical rule: ordinary generators for simulations and games, the cryptographic one for anything a person could gain by predicting.

Common questions

Frequently asked questions

A random number comes from something physically unpredictable, such as thermal noise or radioactive decay. A pseudo-random number comes from an algorithm that starts at a seed and produces a sequence which passes statistical tests but is completely determined by that seed. Almost everything on a computer is the second kind.

They are drawn from the browser's cryptographic generator rather than ordinary Math.random, so the quality is there, but you should still generate key material inside the system that will use it rather than copying a number off any web page. The risk is the transport, not the arithmetic.

Yes, both of them. A range of 1 to 100 can return 1 or 100, and there are 100 possible outcomes rather than 99. The step-by-step panel shows the count so you can check it.

Because that is what randomness looks like. Over a range of 100 the chance of two consecutive draws matching is 1 in 100, so it happens regularly. A generator that avoided repeats would not be random, it would be a shuffle.

It is the skew you get when random bytes are folded into a range using a remainder. Unless the range divides the byte space evenly, the low end of the range collects slightly more of the possibilities. These generators avoid it by discarding out-of-range draws and taking a fresh one instead.

The integer generator takes limits of a few thousand digits, and the decimal version supports up to 999 digits of precision. All the arithmetic runs in exact whole numbers, so nothing is lost past the sixteen or so digits an ordinary decimal number can hold.

These generators are uniform, meaning every value in the range is equally likely. For a distribution that clusters around a middle value, such as heights or measurement errors, you want a normal distribution instead, which the probability calculator handles.

Physical processes that cannot be predicted: atmospheric noise, thermal noise in circuits, radioactive decay timing, or the path of single photons. Random.org samples radio noise and Cloudflare photographs a wall of lava lamps. Raw physical output is usually corrected for bias before being used.

Because the ranges do not divide evenly. A random byte has 256 possible values, and 256 divided by 6 leaves a remainder, so four die faces would appear 43 times per 256 draws and two would appear 42. This generator discards the values in that uneven tail and draws again, which is called rejection sampling and gives a genuinely uniform result.