How Random Number Generators Actually Work (And Why It Matters for Passwords)
Not all "random" is equally random — Math.random() and crypto.getRandomValues() look similar but are built for completely different jobs.
EDTechToolsCenter Editorial"Random" on a computer almost always means pseudo-random — generated by a deterministic algorithm that produces output statistically indistinguishable from true randomness, but not actually random in the physical sense. The important distinction isn't whether it's pseudo-random (nearly everything is), it's whether it's predictable to an attacker.
Math.random() is not built for security
JavaScript's Math.random() uses a fast pseudo-random number generator (PRNG) designed for speed and general use — animations, shuffling a list, picking a random example. Its output can, in principle, be predicted if an attacker knows or can guess its internal state, because it's optimized for performance, not unpredictability. That's completely fine for a game or a UI animation and completely unsafe for anything security-sensitive, like generating a password or a session token.
Sponsored
crypto.getRandomValues() is built for exactly that
The Web Crypto API's crypto.getRandomValues() pulls from a cryptographically secure random source — on most systems, ultimately sourced from real-world entropy the operating system collects (hardware noise, timing jitter, and similar). It's specifically designed so that past output gives an attacker no usable information about future output, which is the actual property you need for passwords, tokens and encryption keys.
Why this matters for a password generator specifically
What this means for you as a user
- For picking a random number for a game, giveaway or non-sensitive decision — any random generator is fine.
- For generating a password, API key, or anything security-relevant — use a tool that's explicitly built on a cryptographically secure random source, not a generic "random number" utility.
- You generally can't tell which one a tool uses just by looking at the output — check that the tool states it uses a cryptographically secure method, since predictable-looking randomness and genuinely unpredictable randomness look identical to the eye.
Tools used in this article
Sponsored
Frequently asked questions
No — it's not designed to resist prediction and shouldn't be used for passwords, tokens, keys or anything where an attacker guessing the output has real consequences.
TechToolsCenter Editorial
How-to Guides
Our editorial desk publishes step-by-step tutorials, comparisons and productivity tips for everyday digital tasks.
Related articles
How to Verify a File's Checksum Before You Trust a Download
A publisher posting a SHA-256 checksum next to a download link is telling you exactly how to check the file wasn't corrupted or tampered with — here's how to actually use it.
MD5 vs SHA-256: What's the Difference and Which Should You Use?
Both turn data into a fixed-length fingerprint, but MD5 is broken for anything security-sensitive while SHA-256 isn't — here's what that actually means in practice.
HTTP vs HTTPS: Why That One Letter Matters
The 's' in HTTPS stands for a real, meaningful difference in how your data travels across the internet — here's what it actually protects.