Solved.tools: Free Online Calculators & Tools

We use cookies for analytics and advertising. Learn more about our cookie policy

Random Number Generator

Last updated: 27 June 2026

Reviewed by Gavin Meiring, Lead research and primary author ยท Doctoral Candidate (Corporate Governance) ยท Research and drafting assisted by AI

Was this helpful?


Random Number Generator

A random number generator produces one or more numbers within a range you define, with no predictable pattern. It is used for games, lotteries, statistical sampling, password generation, decision-making, and classroom activities.

How to Use the Random Number Generator

  1. Enter the minimum value (the lowest number you want to include).
  2. Enter the maximum value (the highest number you want to include).
  3. Enter how many random numbers you want to generate.
  4. Choose whether duplicates are allowed or if all numbers must be unique.
  5. Click Generate to see your random numbers, then click again for a fresh set.

The Formula

Computers cannot produce truly random numbers; they use pseudorandom number generators (PRNGs) based on mathematical algorithms that produce sequences that appear random. The most widely used is the Mersenne Twister algorithm. The formula for generating a random integer between min and max (inclusive) from a uniform random value r between 0 and 1 is: random integer = floor(r multiplied by (max minus min plus 1)) plus min. For cryptographic purposes, truly random seeds sourced from hardware entropy are used instead of purely mathematical PRNGs.

Real-World Example

You want to run a prize draw among 50 employees numbered 1 to 50 and pick 3 winners without repeats. Set minimum to 1, maximum to 50, count to 3, and disable duplicates. The generator might return: 17, 34, 8. These three employees are your winners. If you re-run the generator, the sequence will be different each time because a new seed is used.

Common Uses for Random Number Generators

Random sampling for research surveys (select a random subset from a population). Classroom activities such as random seat assignments, group selection, or quiz question ordering. Game design: random loot drops, map generation, and dice simulations. A/B testing: randomly assign users to control or treatment groups. Security: generate random verification codes, tokens, and session IDs. Decision-making: when faced with equally valid choices, a random result removes bias and analysis paralysis.

Frequently Asked Questions

Are the numbers generated truly random? Most online random number generators use pseudorandom algorithms seeded with system time or hardware events. They are statistically random (pass randomness tests) but are deterministic if you know the seed. For cryptographic security, generators based on hardware entropy sources (such as thermal noise) produce numbers that are computationally indistinguishable from true randomness.

Can the same number appear twice? By default, if you allow duplicates, yes. Each number is drawn independently, so repetition is possible. If you need all unique numbers (as in a lottery or draw), enable the "no duplicates" option. Note that without duplicates, the count cannot exceed the size of the range.

What is the difference between a random number and a random sample? A single random number is one draw from a range. A random sample is a set of numbers selected from a population according to a defined probability rule, such that every member has an equal chance of selection. Generating multiple unique random numbers from a range is equivalent to simple random sampling without replacement.

How do I generate a random decimal number? Set the min and max, then divide the resulting integer by a power of 10. For example, to get a random number between 0 and 1 with two decimal places, generate a random integer between 0 and 100 and divide by 100. Some tools offer a decimal mode directly.

How a range is turned into a number

The generator does not think in terms of dice. It produces a value between zero and one, then maps that value onto your range.

The mapping is one line: result = floor(r multiplied by (max minus min plus 1)) plus min, where r sits between 0 and 1.

Work through a draw with r = 0.7231 over the range 1 to 50. The span is 50 values, so 0.7231 multiplied by 50 is 36.155. The floor of 36.155 is 36. Add the minimum, 1, and the result is 37.

The table shows five draws over the same range.

rr multiplied by 50floorresult
0.00000.00000001
0.01390.69500001
0.500025.0000002526
0.723136.1550003637
0.999949.9950004950

Both endpoints are reachable. A draw just above zero lands on the minimum, and a draw just below one lands on the maximum. The plus one in the formula exists for that reason: without it, the top value of the range would never appear.

Where the mapping goes wrong

Most generators produce a whole number rather than a fraction, and that is where a subtle bias creeps in.

Take a 32-bit generator with 4,294,967,296 possible outputs and a range of 1 to 50. Dividing the two gives 85,899,345 with a remainder of 46. So 50 multiplied by 85,899,345 is 4,294,967,250, and 46 values at the top of the 32-bit space do not divide evenly.

Taking the remainder directly means those 46 values each fall into one extra slot. The result is a small but real bias, about 1 in 85,899,345, or 0.0000012 percent, against the affected numbers. Small numbers like that rarely matter for a prize draw. They matter a great deal in a simulation that runs a billion iterations.

The standard fix is rejection sampling. Discard any raw draw of 4,294,967,250 or above and draw again. The output is then exactly uniform, at the cost of occasionally throwing a value away.

The chance of a repeat in a draw

Turning duplicates off changes the arithmetic of a draw. Independent draws can repeat. Draws without replacement cannot.

The probability that every value is distinct when you draw k numbers from a range of n is the product of n/n, (n-1)/n, and so on down for k terms. Subtract that from one and you have the chance of at least one repeat.

nkchance of no repeatchance of at least one repeat
5030.9408000.059200
5050.8136040.186396
50100.3817070.618293
10050.9034500.096550
365230.4927030.507297
1000400.4536280.546372

The prize draw in the example above uses 50 names and 3 winners. The chance of a repeat if duplicates were allowed is 5.92 percent, which is about one in seventeen. That is why the no-duplicates option exists, and why the count cannot exceed the size of the range once it is switched on.

The fourth column also explains the birthday problem. Twenty three people in a room is enough for a better than even chance that two share a birthday. The mechanics of a random draw are the same.

The generator families and what they cost

Not all pseudorandom generators are built the same way, and the differences show up in speed, memory and statistical quality.

The comparison below draws on the tables published by the PCG project at pcg-random.org and on the generator documentation at prng.di.unimi.it.

familyperiodstate sizenotes
Mersenne Twister2 to the 19937about 2 KBsome failures in statistical tests, easy to predict from output
PCGarbitraryvery compactgood statistical quality, hard to predict, multiple streams
xoshiro256256-bit state256 bitsfast, passes the tests the authors are aware of, not secure
ChaCha202 to the 128about 0.1 KBa stream cipher, usable as a secure generator
Arc4Random2 to the 1699about 0.5 KBsome issues, secure, slow

The Mersenne Twister figure of 2,19937 comes from the PCG project's comparison table. The 256-bit state figure for the xoshiro family comes from the generator page at prng.di.unimi.it, which describes xoshiro256 as the all-purpose choice and notes that it is not cryptographically secure.

That last point is the one that catches people out. A generator that is fine for shuffling a playlist is not fine for producing a session token. The authors of the xoshiro family recommend a stream cipher such as ChaCha20 or AES in counter mode whenever the output has to resist prediction.

Precision in the fractional case

A draw between zero and one with two decimal places comes from drawing an integer from 0 to 100 and dividing by 100. The scale is 100, not 99, because both ends of the interval are wanted.

For three decimal places, draw 0 to 1000 and divide by 1000. For a draw that never returns exactly zero, draw 1 to 1000 instead and divide by 1000.

A shuffle is a draw without replacement

Shuffling a list and drawing unique numbers are the same operation seen from two angles. A shuffle is a sequence of draws without replacement, taken until the list is exhausted.

The number of possible orders grows faster than intuition allows. A list of 5 items has 120 orders. A list of 10 has 3,628,800. A list of 50 has 3.041409e64, which is the same figure quoted in the repeat table above as 50 factorial.

itemspossible orders
5120
103,628,800
202,432,902,008,176,640,000
503.041409e64
528.065818e67

A 52 card deck has 8.065818e67 possible orders. No generator will ever cycle through them all, which is why a shuffle is judged on whether it reaches every order with equal probability rather than on whether it eventually repeats.

Checks to run before you trust a run

Five habits catch most problems with a random draw.

Record the seed with the inputs if the run has to be reproducible. Without it, a dispute about the output cannot be settled.

Confirm the range is inclusive of both endpoints. A draw of 1 to 50 that never returns 50 has an off by one error, and it is the most common defect in a hand written mapping.

Test the smallest possible case. A range of 1 to 1, a count of 1, and a range where the count equals the span are the three cases that break a naive implementation.

Run the draw many times and count the frequency of each value. A fair generator gives each value roughly the same count, and a bias large enough to matter shows up quickly in a few thousand runs.

Check the no-duplicates option against the range size before running. A request for 60 unique numbers from a range of 50 cannot be satisfied, and the tool should refuse rather than loop.

What the tool guarantees and what it does not

The tool returns values inside the range you set, with no pattern a user can see. It does not guarantee a result you cannot predict if you know the seed, and it does not provide the cryptographic strength a password generator needs.

If you need to reproduce a run, record the seed alongside the input. If you need unpredictability against an adversary, use a generator built for it.

Also try these free tools: