Random Number Generator

Generate one or many random integers between a minimum and maximum value. Optionally prevent duplicates — ideal for lottery picks, random sampling, games, and fair draws.

Configure range and click Generate

How It Works

Random number generation for everyday use does not need to be cryptographically secure, but this generator uses window.crypto.getRandomValues() anyway, which eliminates any statistical bias present in Math.random().

Generating a single uniform random integer in [min, max]:
1. Calculate range = max − min + 1 (the number of possible values, inclusive of both endpoints).
2. Generate a random 32-bit unsigned integer R using crypto.getRandomValues(new Uint32Array(1)).
3. Result = min + (R % range).

This gives a uniform distribution over all integers from min to max inclusive.

Generating multiple numbers without duplicates (sampling without replacement):
This uses a Fisher-Yates shuffle on an array of all valid integers, then takes the first N values.
1. Create array [min, min+1, ..., max].
2. Shuffle using Fisher-Yates: for i from (range−1) down to 1, pick random j in [0, i], swap arr[i] and arr[j].
3. Return first N elements.

Fisher-Yates is O(range) time, which is fine for typical ranges but could be slow for very large ranges (e.g., min=1, max=1,000,000, count=5). For large ranges with small counts, a hash-based approach avoids building the full array — but the Fisher-Yates method is used here for simplicity and transparency.

Worked example: Pick 6 numbers from 1 to 49 (lottery).
Build array [1, 2, ..., 49]. Shuffle. Return first 6.
Result might be: 7, 23, 14, 41, 2, 35.
These are guaranteed unique and uniformly distributed.

Generating duplicates: When duplicates are allowed, each number is drawn independently. This means the same number can appear multiple times, with each draw being independent.

Applications: Lottery picks, card dealing, random sampling for surveys, randomizing quiz questions, dice roll simulations, assigning random teams, generating test data.

Frequently Asked Questions

Are the numbers truly random?

They are cryptographically random, generated by the browser's built-in secure random number generator (Web Crypto API). This is as random as your computer can produce without specialized hardware. For statistical purposes, the output is indistinguishable from true random numbers.

Can I generate numbers with decimals?

This generator produces integers only. For decimal numbers, you can generate integers and divide — for example, generate a number from 0 to 1000 and divide by 10 to get one decimal place.

What is the maximum range?

The generator works for any range where max − min + 1 fits in a JavaScript safe integer (up to 2^53 − 1 ≈ 9 quadrillion). Practical performance is best with ranges under 1 million for no-duplicates mode, since that mode builds an array of all values.

Why do I sometimes get repeats even in no-duplicates mode?

The no-duplicates mode physically guarantees no repeats within a single generation. If you generate again, you may see numbers from the previous result because each generation is independent. Repeats only occur across separate generations, not within a single one.

Is this suitable for cryptographic keys or passwords?

For integers, yes — it uses the same secure API. But for passwords specifically, use the Password Generator tool, which assembles characters from a curated character set rather than raw numbers.