Blog
Wild & Free Tools

Cryptographic Random vs Math.random: Which Is Secure?

Last updated: April 2026 7 min read

Table of Contents

  1. The Difference
  2. Why Math.random Is Predictable
  3. Real-World Cases
  4. When Math.random Is OK
  5. How to Tell
  6. Frequently Asked Questions

Almost every "random number generator" website on the internet uses JavaScript's Math.random(). It is one line of code, it works, and for picking a movie tonight it is fine. For lottery picks, password seeds, raffle winners, or anything where the result has value, it is the wrong choice. Here is why, in language non-developers can follow.

free random number generator uses window.crypto.getRandomValues instead — the browser's cryptographic random source. The difference matters more than most people realize.

The Core Difference

Math.random() is a pseudo-random number generator (PRNG). It runs a deterministic mathematical formula starting from a "seed" value. Same seed in, same sequence of "random" numbers out. Fast, reproducible, predictable if you know the seed.

window.crypto.getRandomValues() is a cryptographically secure pseudo-random number generator (CSPRNG). It mixes in real entropy from the operating system — hardware noise, mouse movements, keyboard timing, network jitter — and uses a cryptographic algorithm that cannot be reversed even if you observe many output values.

The key difference: with Math.random, an attacker who sees a few output values can predict the next ones. With crypto.getRandomValues, they cannot — even with infinite compute.

Why Math.random Is Predictable

Pseudo-random algorithms like the one behind Math.random use a small internal state — typically 32 to 128 bits. After observing 5-10 consecutive output values, an attacker can solve for the internal state and predict every future value with 100% accuracy.

Researchers have demonstrated this against most JavaScript PRNGs. There are public proof-of-concept attacks against the Math.random implementations in Chrome, Firefox, and Safari from various browser versions. None of them are theoretical; all have working code.

This is fine when randomness is just for entertainment. It is catastrophic for anything where someone might want to predict your next "random" value.

Sell Custom Apparel — We Handle Printing & Free Shipping

Real-World Cases Where This Matters

For all of these, use crypto.getRandomValues. Always.

When Math.random Is Fine

Use Math.random when:

For everything else, use crypto.getRandomValues. The performance difference is microseconds — invisible to humans.

How to Tell Which a Tool Uses

Most "random number generator" sites do not say which they use. The honest test: open the page in your browser, view the page source (right-click → View Page Source), and search for "Math.random" or "crypto.getRandomValues."

If you see Math.random, the tool is pseudo-random. If you see crypto.getRandomValues, it is cryptographically secure. our random number generator uses the secure source — you can verify by viewing the source.

Some tools call themselves "secure" or "true random" while using Math.random. The check is the source code, not the marketing copy.

Generate Random Numbers Now

Set your range, pick how many, optionally avoid duplicates. Cryptographically secure, runs in your browser, nothing logged.

Open Random Number Generator

Frequently Asked Questions

Is Math.random good enough for lottery picks?

No. Use a cryptographically secure source for anything where the result has value or could be exploited if predicted.

Is window.crypto.getRandomValues truly random?

It is cryptographically secure pseudo-random — statistically indistinguishable from true random for any practical use, including cryptographic key generation.

How can I check if a website uses crypto random?

View the page source and search for "crypto.getRandomValues" or "Math.random". The first is secure; the second is not.

Launch Your Own Clothing Brand — No Inventory, No Risk