Draw a random prime from any range up to one million, every prime equally likely -- for number theory practice, teaching examples, and math games.
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.
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.
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.
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.
The generator will tell you rather than guessing -- ranges like 24 to 28 genuinely hold no primes. Widen the range and draw again.
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.
Number · Roman Numeral · Fraction · Number Fact · Frequency