ToolLineup

Random Prime Number Generator

Generate random prime numbers either from a range you set or at a specific bit size up to 64 bits. Primality is decided by a deterministic Miller-Rabin test with a fixed set of bases, which for numbers in this range gives an exact answer rather than a probabilistic one — including for the Carmichael numbers that defeat naive tests. The count of primes available in your range is shown as you change it. Everything is generated in your browser; nothing is uploaded and no result is recorded anywhere.

How it works

Primality is decided by a deterministic Miller-Rabin test with a fixed set of bases. For values in this range that gives an exact answer, not a probabilistic one — a number reported as prime is prime, including the Carmichael numbers that trip up naive tests.

These are useful for exercises, hash table sizes and test data. Generating a prime for real cryptographic use needs a much larger size than a browser tool should be trusted with.

Values are generated in your browser and never sent anywhere.

25 primes exist between 1 and 100.

Generated primes

Adjust the settings above and values appear here.

Frequently asked questions

Is a number reported as prime definitely prime?

Yes, for the sizes this tool handles. Miller-Rabin is probabilistic in general, but with the specific set of bases used here it is proven exact for every value below roughly 3.3 x 10^24 — far above the 64-bit ceiling of this tool.

What is a Carmichael number and why does it matter?

A Carmichael number is composite but passes the simple Fermat primality test for every base coprime to it — 561 and 1105 are the smallest. A naive prime checker calls them prime; the test used here correctly rejects them.

Can I use these primes for RSA or Diffie-Hellman?

No. Real cryptographic use needs primes of 1024 bits or more, generated inside the system that will use them. These are for exercises, hash table sizes, test data and teaching.

Why does choosing a bit size sometimes take a moment?

Finding a prime of a given size means generating candidates and testing each one. Primes thin out as numbers grow, so a larger bit size means more attempts — the generator forces candidates odd and sets the top bit, which removes the easy misses.

Why does my range contain no primes?

Prime gaps grow with size, and there are stretches of consecutive numbers with none — between 24 and 28, for example. The tool shows how many primes your range contains so you can widen it.

Related tools