Security
Secure Random Number Generator
Secure Random Number Generator produces random integers within a range you choose, using the Web Crypto API's cryptographically secure random number source rather than JavaScript's ordinary Math.random().
It uses rejection sampling to avoid modulo bias, a subtle flaw where a naive modulo-based approach can make some numbers in the range slightly more likely than others. This makes it suitable for security-sensitive randomness, such as generating raffle winners for high-stakes draws, sampling, or seeding cryptographic operations -- unlike the general-purpose Random Number Generator tool, which uses Math.random().
How to Use the Secure Random Number Generator
- Open the Secure Random Number Generator tool.
- Enter the minimum value.
- Enter the maximum value.
- Enter how many numbers you want to generate.
- Click Generate and copy the results.
Frequently Asked Questions
How is this different from the regular Random Number Generator?
The regular Random Number Generator uses JavaScript's Math.random(), which is fast but not cryptographically secure and unsuitable for security-sensitive uses. This tool uses the Web Crypto API (crypto.getRandomValues) with rejection sampling for a properly uniform, cryptographically secure result.
What is modulo bias, and why does it matter?
If you generate a random byte and reduce it modulo a range that doesn't evenly divide 256 (or your byte size), some outcomes become very slightly more likely than others. Rejection sampling avoids this by discarding and re-rolling any value that would introduce that bias, ensuring every number in the range is equally likely.
Is this suitable for generating cryptographic keys directly?
For generating actual secret keys (not just random numbers), use the dedicated Secret Key Generator tool, which outputs properly sized hex/Base64 keys rather than integers.