Random Number in Range
Generate a random integer between any two numbers
99About This Tool
Type a minimum and maximum, hit generate, get an integer somewhere between (inclusive). Useful when you need a quick random pick — sample size of one for an audit, raffle drawing, deciding which of three options to test first.
The randomness comes from the browser's crypto.getRandomValues, which is the standard cryptographically-secure random source. For genuine fairness in raffles or selections that other people care about, that's the right primitive — Math.random() can be predicted from a seed, getRandomValues cannot.
For sequences (multiple unique numbers, no repeats) or weighted picks (some outcomes more likely than others), this single-pick tool isn't the right shape. Use a shuffler or a weighted-random tool for those cases.
The algorithm: getRandomValues fills a Uint32Array with cryptographically-random 32-bit integers. To convert to your range [min, max], the tool rejects values that would create modulo bias (which happens when 2^32 isn't an exact multiple of the range size), then maps the remaining value: result = min + (random_value % range). Rejection sampling guarantees uniform distribution; without it, very small biases would accumulate over millions of picks. For typical use cases the bias is invisible, but the tool implements the rejection step anyway for correctness.
Worked example: pick a winner from 200 raffle entries. Set min=1, max=200, generate. You get, say, 137. That's entry 137. Want to pick 5 winners without replacement? This tool isn't the right shape — it picks one at a time and could legally return the same number twice. Use a shuffler that draws K unique values, or run this tool 5 times and ignore duplicates (which feels right but is actually inefficient at high K-vs-N ratios). For a fair audit sampling 10 of 1000 records: shuffle the record IDs, take the first 10. The single-pick generator works for K=1; sampling without replacement needs a different tool.
What to know about randomness: humans are bad at evaluating it. A genuinely random sequence will contain runs and clusters that feel non-random — five reds in a row at roulette, three of the same number in a small lottery sample. The brain's pattern-recognition fires when no pattern exists. If you generate 100 numbers between 1 and 10 and 'feel' that 7 came up too often, count: it probably came up about 10 times, which is the expected value plus normal variance. Don't fight randomness's clumpy character by picking 'spread out' numbers manually — that intervention introduces actual bias.
For sampling without replacement, the right algorithm is Fisher-Yates partial shuffle. Generate K unique numbers in [1, N] by walking an array and swapping. Time complexity O(K), no rejections, guaranteed uniqueness. Building this on top of the single-pick tool by repeatedly drawing and rejecting duplicates is correct but inefficient — at K = N/2 you're rejecting roughly half your draws. For real applications, use a dedicated shuffler.
The about text and FAQ on this page were drafted with AI assistance and reviewed by a member of the Coherence Daddy team before publishing. See our Content Policy for editorial standards.