CompoundPage

Random number from 1 to 2

One random number from 1 to 2, drawn in your browser from 2 equally likely values and debiased so none of them is favored.

For bingo, balls to call; for a lottery, lines (up to 20).

Draw without replacement, the way a lottery does.

Random number2

Where this came from Your browser's cryptographically secure generator, not Math.random(). V8 implements Math.random() with xorshift128+, whose internal state can be recovered from a short run of its own output. That is fine for shuffling a playlist and unusable for anything anybody would call a secret.
crypto.getRandomValues()
Debiased by 2 divides 2^32 exactly, so every 32-bit word maps to exactly one outcome and plain modulo is already uniform. This is the lucky case and most ranges are not it.
nothing (this range needs none)
Skew avoided How much more likely the favored outcomes would have been under getRandomValues() % range. For small ranges it is far below anything observable; the reason to do it properly is that the same line of code is wrong by nearly 2x for ranges near 2^31, and nobody rewrites it when the range changes.
none for this range
Range size
2 values
Entropy 1 independent draw from 2 values. For comparison, a six-character lowercase password carries about 28 bits and a four-word passphrase from a 7,776-word list about 51.
1.0 bits
  • The numbers in the HTML were drawn once when the site was built, so without JavaScript every visitor sees the same ones. With JavaScript on, which is the normal case, the draw happens in your own browser, from your own generator, and nothing is sent anywhere.

How the Random Number Generator works

This generator draws one integer from 1 to 2 inclusive: 2 possible values, each with probability exactly 1 in 2.

A coin, and the only one of this generator's preset ranges that needs no debiasing at all: 2 divides 2^32 exactly, so every possible 32-bit word maps to one of the two outcomes and plain modulo is already perfectly uniform. It is also the range where a physical coin is measurably less fair than this is: a flipped coin lands on the face it started on slightly more than half the time, around 51%, because it precesses about an axis that is not quite perpendicular to its angular momentum. A spun coin is worse still and depends on the rim.

The draw happens in your browser, from crypto.getRandomValues(), which reads your operating system's cryptographically secure generator. It is not Math.random(): that is xorshift128+ in V8, fast and statistically fine for a game, and predictable to anyone who sees a short run of its output. Nothing about your draw is sent anywhere, because there is nowhere for it to be sent: the page is static and the generator is local.

This range is the easy case. 2 divides 2^32 exactly, so every one of the 4,294,967,296 possible 32-bit words maps to exactly one outcome and there is no bias to remove. Taking the word modulo 2 is already uniform. Most ranges are not like this.

One draw from this range carries about 1.0 bits of entropy. For scale, a six-character lowercase password is roughly 28 bits and anything used as a secret wants 70 or more.

One thing about how the result reaches you: the site is statically hosted, so the number in the HTML was drawn once when the site was built. If you have JavaScript turned off, that is what you are looking at, and every other such visitor sees the same thing. With JavaScript on, the generator redraws immediately from your own browser. A generator that quietly serves one cached "random" value to everybody is broken, which is why the build-time draw is labeled.

Random Number Generator FAQ

How do I get a random number between 1 and 2?

The generator above does it on load and on every press. It draws from your browser's crypto.getRandomValues() and maps the result straight onto the 2 values, which is uniform because 2 divides 2^32 exactly.

Is every number in this range equally likely?

Yes, exactly. 2 divides 2^32, so each outcome has precisely the same number of 32-bit words behind it.

Is there anything particular about this range?

A coin, and the only one of this generator's preset ranges that needs no debiasing at all: 2 divides 2^32 exactly, so every possible 32-bit word maps to one of the two outcomes and plain modulo is already perfectly uniform. It is also the range where a physical coin is measurably less fair than this is: a flipped coin lands on the face it started on slightly more than half the time, around 51%, because it precesses about an axis that is not quite perpendicular to its angular momentum. A spun coin is worse still and depends on the rim.

Can I rely on it not being predictable?

For anything short of a regulated draw, yes. The source is the same operating-system facility that generates cryptographic keys. The limit worth knowing is that it is a CSPRNG seeded from hardware entropy rather than a hardware true-random device sampling a physical process, and no software running in a browser tab can be the latter.

More from the Random Number Generator

Related calculators

Embed this calculator
<div id="compoundpage-random-number-generator"></div>
<script src="https://compoundpage.com/embed/random-number-generator.js" async></script>

The same calculation as JSON