Random Prime Number Generator

Draw a random prime from any range up to one million, every prime equally likely -- for number theory practice, teaching examples, and math games.

What is a prime number?

A prime is a whole number greater than 1 divisible only by 1 and itself; every other whole number is composite. The fundamental theorem of arithmetic says each integer above 1 factors into primes in exactly one way, which makes primes the building blocks of the whole number system. Euclid proved around 300 BCE that they never run out, and they thin as numbers grow, roughly one in every ln(n) integers near n. Their difficulty is now practical as well as theoretical: public-key cryptography rests on multiplying two large primes being easy while reversing that product is not.

About this generator

This generator draws a random prime number from any range you set, up to one million -- every prime in the range equally likely.

Every result here is drawn using crypto.getRandomValues() -- the Web Crypto API's cryptographically secure randomness -- instead of Math.random(), so it's genuinely unpredictable, not just statistically random. Learn more.

What people use it for

Use it for number theory practice, generating examples for teaching divisibility and factorization, picking hash-table sizes or toy cryptography moduli, or math-trivia games.

How it works

Generate sieves all primes inside your range, then picks one uniformly with the site's cryptographically secure randomness. Change the range in the settings popover -- the maximum allowed is 1,000,000.

Common questions

What if my range contains no primes?

The generator will tell you rather than guessing -- ranges like 24 to 28 genuinely hold no primes. Widen the range and draw again.

Is every prime in the range equally likely?

Yes -- all primes in the range are listed first, then one is chosen uniformly at random, so small and large primes have exactly the same chance.

Related Generators

Number · Roman Numeral · Fraction · Number Fact · Frequency

All Math & Numbers generators

Browse all generators