Generate random numbers with min, max, and unique options
Random number generator produces numbers within a specified range with configurable options for integers, decimals, and distribution. Useful for testing, simulations, games, sampling, and any application needing non-cryptographic random values.
Specify minimum and maximum values, choose integer or decimal output, and optionally set decimal places. The tool uses Math.random() × (max - min) + min formula. For integers, the result is rounded. Multiple numbers can be generated at once for batch needs.
Math.random() returns [0, 1) with approximately uniform distribution. Not cryptographically secure. For integers in range [min, max], use Math.floor(Math.random() * (max - min + 1)) + min. Edge cases: ensure min ≤ max, handle negative ranges, consider floating-point precision for decimals.
Generate random test inputs within valid ranges.
Random ages 18-65 for user testingDice rolls, random events, procedural generation.
Random selection from numbered populations.
Distribute requests randomly across servers.
// Integer in range [min, max] inclusive
function randomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
// Float in range [min, max)
function randomFloat(min, max, decimals = 2) {
const num = Math.random() * (max - min) + min;
return parseFloat(num.toFixed(decimals));
}
// Generate array of random numbers
function randomArray(count, min, max, integer = true) {
return Array.from({ length: count }, () =>
integer ? randomInt(min, max) : randomFloat(min, max)
);
}
// Examples
randomInt(1, 6); // Dice roll: 1-6
randomFloat(0, 1, 4); // 0.7234
randomArray(5, 1, 100); // [42, 87, 13, 55, 91]Use different formulas for inclusive vs exclusive bounds. +1 in integer formula includes max value.
Use random number generator for testing, simulations, games, and sampling. For cryptographic needs, use crypto.getRandomValues() instead.
No, it is pseudo-random using a deterministic algorithm (usually xorshift128+). Good enough for most purposes but predictable if seed is known. For cryptography, use crypto.getRandomValues().