Prime Number Generator
RG-11Type a range and press Random primes for a random pick, or List all primes for every prime in it. Numbers can go up to 18446744073709551615.
Runs in your browser. Nothing is uploaded.
Range: lowest and highest on one line (empty means 1 1000)
Primes
How to use it
- Type the lowest and highest number on one line, such as 1 1000. Empty means 1 to 1000.
- For Random primes, choose how many and whether repeats are allowed.
- Press Random primes, or press List all primes to see every prime in the range.
- Copy or download the list.
How primes are found
When the range is up to 5 million numbers wide and ends at 1,000,000,000,000 or lower, the page sieves it to find every prime, then picks from that list, so each prime is equally likely. Above that, it draws random numbers and tests each one with the Miller-Rabin test using fixed bases, which gives an exact answer for any number below 2^64.
Limits
The highest value is 18446744073709551615, or 2^64 minus 1. List all primes works when the range is up to 5 million wide below 1,000,000,000,000, or up to 100,000 wide above that, and shows at most 20,000 primes. If random drawing fails to find enough primes after 200,000 tries, the page stops with an error. 1 is not a prime, and 2 is the only even prime.
Not for cryptographic keys
The primes are random picks from your range, but the page is not meant for creating RSA or other cryptographic keys, which need much larger primes and extra checks. Use it for math practice, test data and puzzles. Values use crypto.getRandomValues, and nothing is stored or sent.
Error messages and what to do
| Message | What it means | Fix |
|---|---|---|
There is no prime number between 24 and 28. | The range holds no prime. | Widen the range. |
Only 25 prime numbers lie between 1 and 100, so 30 different ones are not possible. | No repeats is ticked and the count is higher than the primes available. | Lower the count, widen the range or untick No repeats. |
Questions people ask
How do I generate a random prime number?
Type the range, choose how many you want and press Random primes. Each line is a prime inside your range. Tick No repeats to avoid the same prime twice.
How do I list all primes up to 1000?
Type 1 1000, or leave the box empty, and press List all primes. There are 168 primes up to 1000, one per line.
What is the largest prime this page can generate?
The highest number allowed is 18446744073709551615 (2^64 minus 1). The largest prime below that is 18446744073709551557. Larger numbers are not supported.
Is 1 a prime number?
No. A prime has exactly two divisors, 1 and itself, and 1 has only one. The smallest prime is 2, and it is the only even one.
How does the page know a large number is prime?
It uses the Miller-Rabin test with a fixed set of bases. For numbers below 2^64 that set is known to give the exact answer, so there are no false positives in the supported range.
Can I use these primes for encryption keys?
No. Real key generation needs much larger primes and special care. These are for learning, tests and puzzles only.
About this tool
Random primes: when the range is up to 5 million numbers wide and ends at 1,000,000,000,000 or lower, or is up to 100,000 wide above that, the page finds every prime in it and picks from that list, so each prime is equally likely. Otherwise, up to a highest value of 18446744073709551615 (2^64 minus 1), it draws random numbers and tests each with the Miller-Rabin test using fixed bases, which is exact for every number below 2^64. If it cannot find enough primes after 200,000 tries it stops with an error. List all primes works on the ranges described above and shows at most 20,000 results. 1 is not prime. Larger numbers are not supported. Nothing is stored or sent.