Generate Prime Numbers Online

Generate Prime Numbers List every prime up to 10,000,000 with the Sieve of Eratosthenes. Free, offline, client-side - with density and largest-gap stats.

Generate every prime number up to 10 million using the Sieve of Eratosthenes backed by a Uint8Array. The tool reports how many primes it found, their density, and the largest gap between consecutive primes in your range.

How to Use Generate Prime Numbers Online

  1. Pick an upper limit. Any integer from 2 to 10,000,000. The input defaults to 100, so a fresh page shows the 25 primes up to 100.
  2. Choose an output separator. Comma for inline lists, newline for spreadsheet-ready output (one prime per row), space for URL-friendly strings.
  3. Click Generate Primes or press Ctrl/Cmd+Enter. For limits ≥ 500,000 the button switches to "Sieving…" briefly while the Uint8Array sieve runs.
  4. Read the primes. Every prime up to your limit appears in the output, in order, using your chosen separator.
  5. Scan the stats line. It reports π(limit) = count of primes, density as a percentage, first and last prime, largest gap between consecutive primes, and compute time in milliseconds.
  6. Change format without waiting. Switching the separator re-renders the cached prime list instantly - no fresh sieve pass.
  7. Copy or download. Copy puts the formatted list on your clipboard; Download saves a .txt report with primes, stats, and a timestamped filename.

Frequently Asked Questions

What is the Sieve of Eratosthenes?

An ancient algorithm that finds all primes up to n by iteratively marking multiples of each prime starting from 2. Every number that remains unmarked at the end is prime. For large n, sieving is much faster than trial-dividing every candidate.

What is the maximum limit for prime generation?

10,000,000. At that size the sieve allocates about 10 MB (one byte per index) and runs in 1-2 seconds on a modern laptop. Pushing higher risks allocation failures on low-memory devices.

How fast is the generation?

Very fast. Up to 100,000 it completes in a few milliseconds; up to 1,000,000 in ~30 ms; up to 10,000,000 in 1-2 seconds. The loading state only kicks in for 500k+ to give the UI a chance to repaint.

Can I use different output formats?

Yes – comma, newline, or space. Switching the separator re-renders from the cached prime array instantly, so you can toggle freely without re-sieving.

How many primes are there up to 1 million?

Exactly 78,498 – the famous value for π(10^6). Enter 1,000,000 as the limit and the stats line will confirm the count.

What does “largest gap” mean?

The largest difference between two consecutive primes in your range. For primes up to 100 the largest gap is 8 (between 89 and 97). It’s a quick way to spot prime deserts without scanning the full list.

What does the density percentage mean?

π(n)/n – the fraction of integers up to n that are prime. It drops roughly like 1/ln(n) by the Prime Number Theorem, so density falls from 25% at n=100 to about 7.85% at n=10^6.

Why would I need to generate prime numbers?

Cryptography (RSA/DH key selection), number-theory experiments, primality-test benchmarks, hash-table sizing, coding interview problems, and teaching material for algorithm classes.

Is my data secure and is this tool free?

Yes and yes. The sieve runs 100% client-side – no server call, no analytics on your input, no data retention – and the tool is free with no sign-up or usage caps.

Does this tool work offline?

Yes. After the page has loaded, every sieve runs locally in your browser. Disconnect from the internet and the tool keeps generating primes.