Random Digit Generator
Generate cryptographically secure random digits (0-9) with custom count, range, uniqueness, and separator options. Copy or download results instantly.
About
Pseudo-random number generators (PRNGs) like linear congruential generators suffer from predictable sequences and short periods. This tool uses the Web Crypto API (crypto.getRandomValues) to produce digits sourced from the operating system's entropy pool. The output digits fall within a configurable range from min to max (default 0 - 9). Modulo bias is eliminated through rejection sampling: any raw 32-bit value that exceeds the largest clean multiple of the range width is discarded and redrawn. This guarantees each digit in the range has equal probability to within cryptographic standards.
Misconfigured random generation causes real damage. Weak randomness in PIN codes, OTP tokens, or sampling indices introduces exploitable patterns. If you enable the uniqueness constraint with a count exceeding the range width, generation is mathematically impossible and the tool will warn you rather than silently fail. Note: this tool generates individual digits (single-character values within a range), not multi-digit numbers. For statistical sampling, remember that true independence requires sampling with replacement (uniqueness off).
Formulas
A raw unsigned 32-bit integer r is drawn from crypto.getRandomValues. The range width w is computed as:
To eliminate modulo bias, compute the rejection threshold t:
If r โฅ t, discard and redraw. Otherwise, the unbiased digit d is:
Where min = minimum digit value (default 0), max = maximum digit value (default 9), w = range width, r = raw 32-bit unsigned integer, t = rejection threshold, d = output digit. The probability of rejection per draw is at most w232, which for w โค 10 is negligible (< 0.00000024%).
Reference Data
| Property | PRNG (Math.random) | CSPRNG (crypto.getRandomValues) |
|---|---|---|
| Entropy Source | Algorithmic seed | OS entropy pool (hardware noise) |
| Predictability | Deterministic if seed known | Computationally infeasible to predict |
| Period Length | ~2128 (xorshift128+) | Not periodic (reseeded continuously) |
| Modulo Bias Risk | Yes, if using Math.random ร n | Eliminated via rejection sampling |
| Speed (10k values) | < 1 ms | < 2 ms |
| Suitable for Cryptography | No | Yes |
| Suitable for Games | Yes | Yes (overkill) |
| Suitable for OTP/PIN | No | Yes |
| Suitable for Sampling | Acceptable | Preferred |
| Suitable for Simulation | Yes (reproducible seeds) | Not ideal (non-reproducible) |
| Browser Support | All browsers | All modern browsers (IE11+) |
| Specification | ECMAScript (implementation-defined) | W3C Web Cryptography API |
| Uniform Distribution | Approximately uniform | Provably uniform (with rejection) |
| Digit Range Default | 0 - 9 | 0 - 9 |
| Max Safe Integer | 253 โ 1 | 232 โ 1 per call |