Randomly logo Randomly

Prime number generator

List primes two ways: the first N primes, or every prime within a range. Uses a sieve of Eratosthenes and runs entirely in your browser.

Modes First N · range Method Sieve

Output · 24 primes

Ready

A prime has exactly two divisors: 1 and itself. The “in range” mode uses a sieve of Eratosthenes; “first N” tests candidates one by one. 2 is the only even prime.

A free prime number generator that lists prime numbers two ways: the first N primes, or every prime within a given range. Uses a sieve of Eratosthenes computed locally in your browser. Copy the results as a comma-separated list or line by line.

How to use the prime number generator

  1. Choose a mode: First N primes, or all primes in a range.
  2. Enter N or the lower and upper bounds of your range.
  3. The list of primes appears below.
  4. Use the copy button to export as CSV or a plain list.

How the sieve of Eratosthenes works

Start with a list of integers from 2 to your upper bound. Mark 2 as prime and cross out all its multiples. Move to the next unmarked number (3), mark it prime, and cross out its multiples. Repeat until you pass the square root of the upper bound — all remaining unmarked numbers are prime. The sieve is efficient for generating all primes up to a fixed limit and runs entirely client-side here.

Frequently asked questions

What is a prime number?

A prime number is a whole number greater than 1 that has no positive divisors other than 1 and itself. The first few primes are 2, 3, 5, 7, 11, 13.

Is 1 a prime number?

No. By definition, prime numbers must be greater than 1. The number 1 is called a unit, not a prime.

What is the sieve of Eratosthenes?

An ancient algorithm that finds all primes up to a limit by iteratively marking the multiples of each prime as composite, starting from 2.

How many primes can this generator list?

The practical limit depends on your browser and device memory. Generating primes up to a few million is typically instant; beyond that it may take a second or two.

Is 2 the only even prime?

Yes. Every even number greater than 2 is divisible by 2 and therefore composite.

Other tools