Inclusive vs exclusive ranges
This tool treats both bounds as inclusive: a range of 1 to 6 can produce 1, 2, 3, 4, 5 or 6. Many programming APIs use exclusive upper bounds instead, which is the source of countless off-by-one bugs in game logic and test data.
// inclusive both ends, unbiased
function randomInt(min, max) {
const range = max - min + 1;
const MAX = 0x100000000;
if (!Number.isSafeInteger(range) || range < 1 || range > MAX) throw new RangeError("range too large");
const buffer = new Uint32Array(1);
const limit = Math.floor(MAX / range) * range;
let value;
do { crypto.getRandomValues(buffer); value = buffer[0]; } while (value >= limit);
return min + (value % range);
}
Math.floor(Math.random() * (max - min + 1)) + min works for casual use, but Math.random is not cryptographically secure and the mapping can be biased for large ranges.
Unique numbers
When you need a set of distinct values — lottery draws, sampling without replacement, test IDs — enable the unique option. The generator rejects duplicates by retrying with the same uniform sampler. If you request more values than the inclusive range contains, the result is capped at the range size and the UI says so.
Decimals and precision
Decimal output uses the requested number of decimal places. Binary floating-point cannot represent every decimal exactly, so values are rounded for display. If the number feeds a calculation that requires exact decimals, use integers scaled by a factor instead.