Random Number Generator

Generates one or more random whole numbers between a user-set minimum and maximum, with both bounds included in the possible results. Each draw calls the browser's built-in Math.random, then maps the result with the formula n equals min plus floor of r times (max minus min plus 1), giving every integer in the range an equal chance. Inputs are the minimum, the maximum, and how many numbers to draw, from 1 to 20.

Your numbers

Set a lower bound, an upper bound and how many numbers you want, and the generator draws that many whole numbers from the range, with both endpoints possible. Read the result as a plain list, one line per pick. Each pick is independent and drawn fresh, so a value can repeat within the same batch. Everything runs locally in your browser, nothing is stored, and changing any input triggers a new draw that has no connection to the last one.

A short history of drawing lots

Long before anyone spoke of algorithms, people needed a fair way to decide, divide or sample, and they reached for physical objects whose outcome nobody could steer. The oldest of these are astragali, the small ankle bones of sheep and goats, thrown like dice across the ancient Near East and the Mediterranean thousands of years ago. Cubic dice and the casting of lots followed, and drawing lots to settle a choice appears throughout classical and religious texts. The mathematics arrived late. Gerolamo Cardano wrote the first systematic treatment of games of chance, Liber de ludo aleae, around 1564, defining odds as the ratio of favourable to unfavourable outcomes, but the manuscript stayed unpublished until 1663, long after his death. The decisive moment came in 1654, when Blaise Pascal and Pierre de Fermat exchanged letters about how to split the stakes of an interrupted game and worked out that the answer depends on the ways the game could still have gone rather than on how it had gone so far. Christiaan Huygens turned that reasoning into the first printed treatise on probability in 1657. It is that body of theory which lets a tool like this one promise every integer an equal share of the outcomes.

The move from objects to written tables came with modern statistics. In 1927 the English statistician L.H.C. Tippett published a set of random sampling numbers, over forty thousand digits he had taken from census area figures, so researchers could draw samples without bias. In 1938 and 1939 Maurice Kendall and Bernard Babington Smith went further, building a spinning disc lit by a flashing lamp to produce a hundred thousand digits by machine; along the way they set out the frequency, serial, gap and poker tests still used to judge whether a sequence looks random. The most cited table of all came from the RAND Corporation, which began production in 1947 on an electronic device that behaved like a roulette wheel and published the result through the Free Press in 1955 as A Million Random Digits with 100,000 Normal Deviates, a book whose title is a complete description of its contents. Physical generators never disappeared. On 1 June 1957 the United Kingdom ran its first Premium Bonds draw with ERNIE, the Electronic Random Number Indicator Equipment, built at the Post Office Research Station by a team that included Tommy Flowers and Harry Fensom, both veterans of the wartime Colossus machines. ERNIE 1 took its digits from the noise inside neon gas discharge tubes. The fifth machine in the line, running since March 2019, draws on quantum optical noise instead and still produces the monthly result.

How each number is drawn

A computer has no roulette wheel inside it, so it produces randomness with arithmetic. One call to JavaScript's built-in Math.random returns a value r that is at least 0 and always below 1. The draw maps that value onto your range:

n = min + ⌊r × (maxmin + 1)⌋

With the defaults of 1 to 100 and a count of 1, the range spans 100 − 1 + 1 = 100 integers. Suppose r comes back as 0.4237. Then 0.4237 × 100 = 42.37, the floor brackets cut that down to 42, and adding the minimum gives 43. Because r never reaches 1, the floored product tops out at 99 and the result never exceeds 100; because r can be exactly 0, the result can be exactly 1. Each of the 100 integers owns an equal slice of r's territory, so the distribution is uniform.

Pseudo-random is not the same as random

The arithmetic behind Math.random is old in computing terms. Around 1946 John von Neumann proposed the middle-square method, squaring a number and keeping its middle digits as the next value; he set it out publicly at a 1949 conference whose papers reached print in 1951. In that same period D.H. Lehmer described the multiplicative generator that still carries his name, which repeatedly multiplies and takes a remainder, published in 1951. The extra additive constant that turns Lehmer's scheme into the linear congruential generator came later, in work published by W.E. Thomson and A. Rotenberg in 1958. Von Neumann knew how uneasy the whole idea was, remarking that "anyone who considers arithmetical methods of producing random digits is, of course, in a state of sin." His point still holds: feed such a generator the same starting value, called the seed, and it produces the same sequence every time.

The generators improved enormously. In 1997 Makoto Matsumoto and Takuji Nishimura introduced the Mersenne Twister, whose standard MT19937 form does not repeat until after 219937 − 1 steps, a period no application could ever exhaust. In July 2003 George Marsaglia introduced the xorshift family in the Journal of Statistical Software, fast generators that stir their state with bit shifts and exclusive-or operations, and Sebastiano Vigna later refined these into a variant called xorshift128+, which carries 128 bits of state and clears the TestU01 statistical suite. That is the algorithm your browser runs. V8, the engine in Chrome, swapped its old Math.random for xorshift128+ in version 4.9.41.0, announced on 17 December 2015 and delivered to users in Chrome 49; Firefox and Safari draw from the same class of generator. The browser seeds it once, and from then on the whole sequence is determined by a hidden internal state; it looks random only because each step scrambles that state thoroughly. For deciding who goes first, drawing a raffle winner among friends, shuffling flashcards or generating test data, this is the right tool, with solid statistics and effectively no cost.

Where it is the wrong tool

Two jobs need a stronger source. Cryptography is the obvious one: passwords, session tokens and keys must come from crypto.getRandomValues or an equivalent, because an attacker who reconstructs the xorshift128+ state can predict every future output. The second is any draw with real stakes. Gambling is licensed country by country rather than by any single international authority, and the European Union in particular has no gambling regulator of its own, leaving the matter to each member state. Even so, the licensed operators in Great Britain, the United States, Canada and Australia work under rules of the same shape: the generator has to be examined by an independent test house, its statistical behaviour has to stand up to inspection, and the draw has to leave a record an auditor can follow afterwards. A call to Math.random in a web page satisfies none of that. There is also a practical mismatch for lottery lines: this tool allows repeats, while a ticket needs distinct numbers.

Inclusive bounds and off-by-one traps

Programming idioms usually exclude the top of a range, which trains people to expect 0 through 9 from "random 10". This generator includes both ends, so the count of possible outcomes is always max − min + 1.

Settings Possible values Outcomes
1 to 100 1 through 100 100
0 to 9 0 through 9 10
−5 to 5 −5 through 5 11
7 to 7 7 only 1

A range of a single value is legitimate and simply returns that value every time. Setting the minimum above the maximum leaves no integers to choose from, and the calculator reports that as an error rather than guessing what you meant.

Two smaller rules are worth knowing. If a bound arrives with a fractional part it is pulled inward to the nearest whole number that still lies inside the range, so the minimum rounds up and the maximum rounds down, and the span never grows beyond the interval you asked for. The batch size is rounded to a whole number and then held between 1 and 20, so a request for fifty picks returns twenty.

Frequently asked questions

Is Math.random actually random?

No, it is pseudo-random. Chrome, Firefox and Safari all implement it with an algorithm called xorshift128+, which starts from a hidden seed and then produces a fully determined sequence that merely looks random. The output passes standard statistical tests, so for games, sampling and everyday picks the difference never shows.

Are the minimum and maximum included in the results?

Yes, both bounds can come up. With the default range of 1 to 100 there are exactly 100 possible values and each one has a 1 in 100 chance on every draw. Some other tools exclude the upper bound, which is why identical settings can behave differently elsewhere.

Why do I get the same number more than once?

Each draw is independent, so repeats are allowed and genuinely expected. Ask for 20 numbers between 1 and 100 and there is about an 87% chance that at least one value appears twice, the same birthday-paradox effect that makes shared birthdays common in small groups. If you need distinct values, redraw or strike the duplicates by hand.

Can I use this to pick lottery numbers to play?

For choosing which numbers to put on your own ticket, yes, and the picks are as good as any others because every combination is equally likely. What nobody should do is use Math.random to run a draw where money changes hands, since the generator is not certified, not auditable and technically predictable. Licensed lotteries use certified hardware generators for exactly that reason.

How do I simulate rolling dice with this?

Set the minimum to 1, the maximum to 6 and the count to the number of dice. Each face has a 1 in 6 chance, about 16.7%, and the calculator lists every die separately so you can add them up. For the twenty-sided die used in tabletop games, set the maximum to 20 instead.