Generate random numbers within any custom range. Set your minimum, maximum, and quantity — up to 1,000 numbers at once. Copy results instantly.
Set range and generate numbers
Random numbers underpin statistical sampling, cryptographic security, game development, and algorithmic simulation. Depending on the application, computers generate numbers using either Pseudo-Random Number Generators (PRNGs) or Cryptographically Secure Pseudo-Random Number Generators (CSPRNGs).
| Feature | Standard PRNG (e.g., Math.random()) | CSPRNG (e.g., Web Crypto API) |
|---|---|---|
| Underlying Algorithm | xorshift128+, Mersenne Twister | ChaCha20, AES-CTR DRBG |
| Entropy Source | Internal state register | Hardware noise, OS entropy pool |
| Predictability | Predictable if internal state observed | Mathematically unpredictable |
| Performance | Extremely fast (nanoseconds) | Highly optimised, secure |
| Primary Use Case | Graphic animations, casual gaming | Cryptography, token generation, lotteries |
When mapping raw random bytes into an integer range $[\text{min}, \text{max}]$, using simple modulo arithmetic introduces modulo bias unless the range divides the entropy space evenly.
To guarantee zero statistical bias, modern generators apply rejection sampling:
$$N_{\text{range}} = \text{max} - \text{min} + 1$$ $$\text{Limit} = 2^{32} - (2^{32} % N_{\text{range}})$$
Any random 32-bit sample greater than or equal to $\text{Limit}$ is discarded and re-sampled, ensuring each candidate integer possesses an identical probability of selection.
JavaScript (Cryptographically Secure)
function secureRandomInt(min, max) {
const range = max - min + 1;
const maxUint32 = 0xFFFFFFFF;
const limit = maxUint32 - (maxUint32 % range);
const buffer = new Uint32Array(1);
let randomVal;
do {
crypto.getRandomValues(buffer);
randomVal = buffer[0];
} while (randomVal >= limit);
return min + (randomVal % range);
}
Python
import secrets
def get_secure_random(min_val: int, max_val: int) -> int:
# secrets.randbelow uses cryptographically secure rejection sampling internally
return min_val + secrets.randbelow(max_val - min_val + 1)
This website and utility are provided for general informational, calculation, and educational purposes only. Always verify critical computation outputs prior to professional deployment or financial use. See our Terms of Service and Privacy Policy for full governance details.