CruxDevCruxDev Tools Prompts
dev Utility • Zero-Server Privacy • 100% Client-Side

Prime Number Generator & Checker

Generate every prime in a range up to 10,000,000 with a sieve, and check any single number for primality - counts, first, and last prime included.

Overview

Generates every prime number in a range up to 10,000,000 with a sieve of Eratosthenes, and checks any single number for primality on demand. The result shows the count, the first and last primes, and the full list, click-to-copy. All computation is local and instant - no lookup tables, no API.

How It Works

Set the range start and end - capped at ten million so the sieve stays instant - and the list computes as you type, with count, first, and last shown above it. Click the output to copy the whole list as comma-separated text. The primality checker below takes any integer and answers prime or not prime immediately, which is handy for spot-checking numbers far beyond sieve range.

Step-by-Step Usage Guide

  1. Enter the start of your range (1 is fine) and the end, up to 10,000,000.
  2. Read the count, first, and last summary before copying the list.
  3. Click the output area to copy all primes as comma-separated text.
  4. Use the primality checker for individual numbers, including large ones outside sieve range.

Technical Specifications & Standards

The generator is the sieve of Eratosthenes over a Uint8Array: mark multiples of each surviving number starting from its square, and what remains is prime. It remains the fastest way to enumerate all primes below a few tens of millions, running in well under a second for the ten-million cap, with memory of one byte per candidate. The checker uses trial division by six-plus-or-minus-one steps - after eliminating multiples of 2 and 3, every prime is of the form 6k±1, so the loop tests two candidates per increment up to the square root. That makes a check of a number like 7919 finish in a handful of iterations, and it is exact for any integer JavaScript can represent exactly, with no probabilistic false positives. Counting primes in a range this way also demonstrates prime density informally: the count below 10,000,000 is 664,579, a number worth knowing when sanity-checking a generator you wrote yourself.

Targeted Use Cases

  • Grabbing test data for hash functions, modular arithmetic, or RSA-style examples in code exercises.
  • Checking homework or puzzle answers: is 7919 prime, and what are the primes between 1000 and 1100?
  • Estimating prime density over an interval for a maths lesson or a blog illustration.
  • Feeding a list of small primes into a wheel factorisation or hashing implementation.

Notes & Gotchas

  • Keep the range end as low as your question needs; a sieve to 10,000,000 is fast but a sieve to 1,000 is faster.
  • Copy the list rather than re-typing it - transcription errors in prime tables are a classic debugging trap.
  • The checker is exact, not probabilistic, so trust its verdict on any integer you enter.
  • For primes above 10,000,000 use the checker, not the range; a full sieve that high stops being a browser-sized job.

Frequently Asked Questions

How fast is the generator?

The sieve to 10,000,000 completes in a fraction of a second in a browser tab. Narrow ranges are effectively instant because the work scales with the end of the range.

Is the primality check probabilistic?

No. It is deterministic trial division up to the square root using the 6k±1 form, so its answer is exact for any integer - unlike Miller-Rabin-style tests which trade certainty for speed on huge numbers.

Why is the range capped at 10,000,000?

The sieve allocates one byte per candidate; beyond ten million the memory and time stop being a pleasant browser experience. The checker remains available for individual larger numbers.

Why does 1 not count as a prime?

By definition primes have exactly two distinct divisors. 1 has only one, so it is neither prime nor composite - every factorisation algorithm relies on this, and the tool follows it.