Random Number Generator for Integer Ranges
Generate random integers within an entered range. Choose the quantity and available uniqueness or sorting options, then review the results.
Random Number Generator workspace
Cryptographic Strength
Uses `crypto.getRandomValues` — the browser's Web Crypto API — not `Math.random()`. Suitable for raffles, security tokens, and statistical sampling.
No Modulo Bias
Naive `bytes % range` skews the distribution on non-power-of-two ranges. We use rejection sampling against a 32-bit limit so every value in the range is equally likely.
Up to 10,000 Numbers
Generate a single value or a list of 10,000. Optional uniqueness constraint (no repeats), optional ascending sort, and one-click copy of the full list.
100% Client-Side
Random bytes are sourced from your local browser. Raffle picks, lottery numbers, and sampling results never leave your device — provably fair, provably private.
Random Number Generator: Unbiased Integers in Any Range
Generate random integers within an entered range. Choose the quantity and available uniqueness or sorting options, then review the results. A unique batch cannot contain more values than exist in the selected integer range. Sorting changes presentation, not how the numbers were selected. This utility produces numbers; systems needing tokens, keys, or audited draws require their own format and process controls.
How to use the random number generator
- Set Min and Max — both are inclusive, so 1 to 6 covers every die face.
- Set How many from 1 to 10,000 — values above the cap are clamped down, below 1 are clamped up.
- Turn on Unique (no repeats) for lottery picks or sampling where each value must differ.
- Turn on Sort ascending to return the list in order instead of draw order.
- Press Generate, or click a preset (coin flip, D20, Powerball 5/69) to load and run canonical settings in one click.
- Press Copy to send the comma-separated result to your clipboard.
How a secure random number generator works
There are two classes of source. A non-cryptographic PRNG like JavaScript's Math.random() is fast and deterministic from an internal seed — fine for shuffling a deck or jittering an animation, but predictable and never safe for tokens or secrets. A CSPRNG (cryptographically-strong PRNG) like crypto.getRandomValues draws from the operating system's entropy pool and resists prediction. MDN's Web Crypto reference states it directly:
"Math.random() does not provide cryptographically secure random numbers. Do not use them for anything related to security. Use the Web Crypto API instead, and more precisely the Crypto.getRandomValues() method."— MDN Web Docs, Crypto.getRandomValues()
This tool uses crypto.getRandomValues(new Uint32Array(1)) per draw. To map a raw 32-bit value into your range without skew, it computes a rejection limit and re-rolls any value at or above it:
const range = (max - min) + 1; // inclusive
const limit = 2 ** 32 - (2 ** 32 % range);
let n;
do {
n = crypto.getRandomValues(new Uint32Array(1))[0];
} while (n >= limit); // reject the skewed tail
const result = min + (n % range); // uniformWorked examples: settings → output
Coin flip · min 0, max 1, count 1
0
Powerball 5/69 · min 1, max 69, count 5, unique, sorted
7, 23, 41, 52, 68
Test data · min 0, max 100, count 10 (repeats allowed)
88, 12, 88, 4, 57, 91, 12, 30, 76, 5
Edge case · modulo bias vs CSPRNG
Writing crypto.getRandomValues(...)[0] % 100 looks correct but is biased: 2³² = 4,294,967,296 divided by 100 leaves a remainder of 96, so values 0–95 land from 42,949,673 raw inputs while 96–99 land from only 42,949,672. The skew is tiny per draw but fails a chi-squared test over a large sample. Asking for more unique values than the range holds (say 100 unique in 1–50) returns a clear error instead of looping forever.
Preset reference: bounds and behaviour
The preset chips load these exact settings and run immediately. Min and max are inclusive; "unique" forbids repeats and "sorted" returns ascending order.
| Preset | Range | Count | Unique | Sorted |
|---|---|---|---|---|
| Coin flip | 0–1 | 1 | No | No |
| Six-sided die | 1–6 | 1 | No | No |
| D20 | 1–20 | 1 | No | No |
| Powerball 5/69 | 1–69 | 5 | Yes | Yes |
| UK Lottery 6/59 | 1–59 | 6 | Yes | Yes |
| 0–100 (test data) | 0–100 | 10 | No | No |
The browser limit and the rejection cap most tools never mention
The Web Crypto spec throws a QuotaExceededError if you ask getRandomValues for more than 65,536 bytes in a single call. This tool sidesteps that entirely by requesting one Uint32Array(1) (4 bytes) per draw, so even a 10,000-number run stays far under the quota.
There is a second guard buried in the math. Rejection sampling could in theory loop forever, so the generator caps re-rolls at 64 attempts; on the astronomically unlikely 64th miss it falls back to plain modulo with negligible bias. With a real CSPRNG the chance of even two consecutive rejections is below 0.25% for typical ranges, so the cap never fires in practice — it is a defensive belt, not a behaviour you will see.
Related randomness & developer tools
Random globally-unique identifiers
Password GeneratorCSPRNG-backed secret strings
Password Strength MeterCheck the entropy of a secret
Hash GeneratorSHA / MD5 digests from any input
HMAC GeneratorKeyed message authentication codes
Number Base ConverterConvert results to hex, binary, octal
QR Code GeneratorEncode a random code into a QR
Cron Expression BuilderSchedule randomized job runs
HTTP Status CodesReference for API responses
Guide: Strong PasswordsWhy length beats complexity
All ToolsBrowse the full Toolk hub
Last updated: September 15, 2026 · Runs 100% in your browser — no uploads, tool input is not sent to Toolk.
Frequently asked questions
Why does the generator use rejection sampling instead of a simple modulo?
A naive <code>rawValue % range</code> is biased whenever 2³² is not an exact multiple of your range: for a 1–100 draw, values 0–95 each get 42,949,673 possible raw inputs while 96–99 get one fewer. The tool computes a rejection limit and re-rolls any draw at or above it, so every value in [min, max] lands with identical probability.
What happens if I ask for more unique numbers than the range holds?
Requesting, say, 100 unique values between 1 and 50 is impossible, so instead of looping forever the tool returns a clear error telling you to widen the range or lower the count. Repeats are only allowed when the Unique toggle is off.
Do my ranges or generated lists reach a server?
No. Random bytes are produced locally in your browser by crypto.getRandomValues and copied with the native clipboard, so tool input is not sent to Toolk. Toolk's page analytics never receive the bounds, counts, or output lists you work with here.
Is this suitable source material for passwords or API keys?
The underlying CSPRNG is the right family of randomness — nothing like Math.random — but this tool outputs plain integers in a range. For ready-to-use secrets, run Toolk's password generator (/tools/password-generator), which maps the same secure bytes into character sets with guaranteed per-set coverage.