CodeKitHub
English
We checked what RNG popular password generators actually use — some use Math.random()

We checked what RNG popular password generators actually use — some use Math.random()

Published Aug 21, 2026

A password generated with Math.random() and one generated with crypto.getRandomValues() can look identical — same length, same character mix, same entropy count on the label. The difference is invisible until someone with the right knowledge of your browser’s PRNG state tries to predict the next output, which is exactly the scenario a password generator exists to defend against. We instrumented several popular free password generators to see which one they actually call, rather than trusting a marketing page’s claim of being “secure.”

What we tested and how

Directly grepping a site’s source code for Math.random or getRandomValues is unreliable — modern sites bundle and minify JavaScript, and the string might be buried in a vendor chunk or absent entirely if it’s computed dynamically. Instead, we patched both functions in the browser console before clicking each site’s “generate” button, so we could see which one actually got called at runtime:

var origMath = Math.random;
Math.random = function () { window.__mathCalled = true; return origMath(); };
var origCrypto = crypto.getRandomValues.bind(crypto);
crypto.getRandomValues = function (arr) { window.__cryptoCalled = true; return origCrypto(arr); };

Then we clicked each site’s generate/refresh button and checked which flag got set.

What we found

Site Calls Math.random() Calls crypto.getRandomValues()
passwordsgenerator.net Yes No
LastPass (lastpass.com/features/password-generator) Yes No
1Password (1password.com/password-generator) Yes No
CodeKitHub Password Generator No Yes

Three widely used free password generator pages — including the public web tools from two well-known password manager companies — call Math.random() and never touch crypto.getRandomValues() when you click generate.

The important caveat: this is about the marketing-site tool, not the vault

This needs to be stated precisely, because it’s easy to overstate: what we tested is each company’s public, no-login web page that generates a password for anyone to copy. We did not test — and this data says nothing about — the random-generation code inside LastPass’s or 1Password’s actual desktop app, browser extension, or vault, which may be an entirely separate codebase written to a different, stricter standard. Password managers have every incentive to get this right inside the product you pay for and trust with your vault; a marketing-site widget is a much lower-stakes piece of code that may simply not have gotten the same scrutiny.

So the accurate claim is: LastPass’s and 1Password’s free public password-generator web pages use Math.random(), not LastPass and 1Password are insecure. Those are very different statements, and only the first one is something we actually verified.

Does Math.random() actually make a password guessable?

Math.random() is a pseudorandom number generator (PRNG) — in most modern JS engines it’s the xorshift128+ algorithm — designed for speed and statistical distribution, not unpredictability against an adversary. Per Mozilla’s own MDN documentation on Math.random(), it “is not suitable for cryptographic purposes” — this isn’t a disputed claim, it’s stated directly by the API’s own reference documentation. Academic and independent research has shown that observing a handful of consecutive Math.random() outputs from a given engine can be enough to reconstruct its internal state and predict future outputs.

crypto.getRandomValues(), part of the W3C Web Cryptography API, is backed by the operating system’s cryptographically secure random number source and carries no such prediction risk.

In practice, exploiting this against a single generated password requires an attacker to already be running JavaScript in the same browser context and to have captured enough prior Math.random() output to reconstruct the PRNG state — a real but narrow attack surface, not something that happens by a stranger guessing your password from nothing. It’s a legitimate “should be fixed” issue, not an active five-alarm vulnerability for most users’ day-to-day password generation.

What to actually do with this

If you’re generating a password to paste into a form right now, the practical risk from any of the tools we tested is low for a typical one-off use. But there’s no reason to accept the weaker guarantee when the fix is trivial: prefer a generator that explicitly uses crypto.getRandomValues() — or better yet, use your password manager’s actual built-in vault generator rather than its public marketing-site page, since that’s the code path the company has the most incentive to get right. Our own Password Generator uses crypto.getRandomValues() and runs entirely in your browser with nothing sent to a server.

← Back to Blog