A password generator that uses Math.random() in JavaScript is not cryptographically secure — and the practical consequence isn't theoretical: a password generated with a weak PRNG has significantly less entropy than its length suggests, making it guessable with far less effort than a truly random password of the same length
The previous articles on this site covered why complex passwords still get cracked, password managers, passkeys, and why unique passwords matter. This article addresses password entropy and randomness quality — specifically what entropy means, how pseudorandom number generators differ from cryptographically secure ones, and how to evaluate whether a password generator can be trusted.
What password entropy actually measures
Entropy in the context of passwords measures the theoretical difficulty of guessing the password by brute force. It's calculated as:
Entropy (bits) = log₂(character set size ^ password length) = password length × log₂(character set size)
Examples:
- 8 lowercase letters: 8 × log₂(26) = 8 × 4.7 = 37.6 bits
- 8 mixed-case + digits + symbols (charset ~94): 8 × log₂(94) = 8 × 6.55 = 52.4 bits
- 16 mixed-case + digits + symbols: 16 × 6.55 = 104.8 bits
Higher entropy = more guesses required to find the password. 128-bit entropy requires 2^128 guesses in the worst case — beyond practical brute force with any foreseeable hardware.
But entropy calculations assume truly random character selection. If the generator uses a weak PRNG, the actual entropy is the entropy of the PRNG's seed — not the theoretical entropy of the password space.
Math.random() vs crypto.getRandomValues(): what the difference means
Math.random() in JavaScript is a pseudorandom number generator — it produces a deterministic sequence of numbers that appears random but is derived from an internal seed. Key properties:
- The seed is typically based on current time and a few other system values
- The sequence is reproducible if the seed is known
- The algorithm (V8 uses xorshift128+) is not designed for cryptographic security
- Researchers have demonstrated predicting
Math.random()output from a small number of observed values
crypto.getRandomValues() (available in all modern browsers and Node.js) uses the operating system's cryptographically secure random number generator — the same source used for TLS key generation, cryptographic nonces, and other security-critical operations:
- Seed comes from hardware entropy sources (CPU thermal noise, interrupt timing, hardware RNG chips)
- Output is not predictable from a sequence of observed values
- Designed specifically for security-critical randomness
The practical difference for password generation:
Math.random()effective entropy: limited by the PRNG seed entropy, often much less than the theoretical maximumcrypto.getRandomValues()effective entropy: equal to the theoretical calculation based on character set and length
What "256 bits of entropy" means for a password generator
High-quality password generators typically aim for 128 bits of entropy as a practical minimum for generated passwords — this is the threshold commonly considered resistant to brute-force attack even with extremely fast hardware and quantum computing considerations.
At 128 bits of entropy with a 94-character set: password length needed = 128 ÷ log₂(94) = 128 ÷ 6.55 ≈ 19.5 characters → 20-character passwords.
At 128 bits with lowercase only (26 chars): 128 ÷ 4.7 ≈ 27 characters — which is why lowercase-only passwords need to be much longer to achieve the same security.
At 256 bits: the "overkill" threshold that would resist theoretically powerful future attacks — a 39-character mixed-charset password or a 55-character lowercase password.
Diceware and physical randomness
Diceware is an alternative password generation method that uses physical dice to introduce randomness — completely removing any concern about PRNG quality:
- A wordlist of 7,776 words (6^5 — one 5-dice roll per word) is published
- You roll five dice per word and look up the corresponding word
- A passphrase of 6-7 Diceware words (rolled with genuine dice) provides approximately 77-90 bits of entropy from truly physical randomness
Diceware provides mathematically verifiable randomness because you can inspect and audit every step of the process. The resulting passphrases ("correct horse battery staple" style, as popularized by xkcd) are more memorable than random character strings while being similarly secure at equivalent entropy.
The tradeoff: Diceware is slow (rolling dice and looking up words takes time) and requires the wordlist to be available. Software generators with crypto.getRandomValues() are practically equivalent in security and much faster.
Password length vs complexity: what actually matters more
Length increases entropy faster than adding character types:
- 12 lowercase letters: 12 × 4.7 = 56.4 bits
- 12 mixed + symbols: 12 × 6.55 = 78.6 bits (22 bits gain from complexity)
- 16 lowercase letters: 16 × 4.7 = 75.2 bits (18.8 bits gain from length alone)
- 20 lowercase letters: 20 × 4.7 = 94 bits
Adding special symbols adds about 1-2 bits per character (expanding the charset from 62 to 94 adds log₂(94/62) ≈ 0.60 bits per character). Adding 4 characters of length to lowercase-only adds 4 × 4.7 = 18.8 bits. Length consistently wins.
The practical implication: a 20-character lowercase password is more secure than a 12-character complex password, despite being "simpler." The character complexity requirements from 1990s-era password policies optimized the wrong variable.
How to use the Password Generator on sadiqbd.com
- Verify the generator uses
crypto.getRandomValues()(notMath.random()) — the tool uses the browser's cryptographic API for all randomness - Choose 20+ characters for high-security accounts; 16 characters with full charset (uppercase + lowercase + digits + symbols) provides strong security for most purposes
- All generated passwords run client-side only — no passwords are transmitted to or stored by the server; generation happens entirely in your browser
Frequently Asked Questions
How do I know if a password generator online is actually using a secure random source?
Check the source code — reputable tools disclose their implementation, and you can inspect browser-based tools using developer tools (F12 → Sources). Look for crypto.getRandomValues(), window.crypto.getRandomValues(), or Node.js's crypto.randomBytes(). Any tool using Math.random() for password generation should be avoided for security-sensitive passwords. Tools that don't expose their source code should be treated with more skepticism. The safest option for maximum security: use a well-audited open-source password manager's built-in generator (Bitwarden, KeePass) where the random source is publicly documented and independently reviewed.
Is the Password Generator free? Yes — completely free, no sign-up required.
Try the Password Generator free at sadiqbd.com — generate strong, cryptographically secure passwords with custom length and character sets.