Random Prime Generator
Pick random prime numbers from any range.
Random Prime Number Generator
Generate random prime numbers between any two bounds. A prime is a whole number greater than 1 that is divisible only by 1 and itself – 2, 3, 5, 7, 11, 13 and so on. This generator picks primes at random from your range, from two-digit primes for homework to 15-digit primes for programming exercises.
Features
- Any range up to 9,007,199,254,740,991, JavaScript's largest safe integer.
- No repeats option to get distinct primes.
- Presets for 2-digit, 6-digit and 15-digit primes.
- Sorting ascending or descending and a choice of separators.
- Exact results – every number is verified with a deterministic primality test.
How random primes are found
For ranges of up to two million numbers the tool first lists every prime in the range and then draws from that list, so every prime has the same chance. For huge ranges listing would be too slow, so it draws random candidates and tests each one with the Miller–Rabin algorithm. By the prime number theorem, roughly one number in 37 near 10^15 is prime, so a result is found after a few dozen tries.
Uses for random primes
Primes are the building blocks of number theory. Teachers use random primes for factorisation and divisibility exercises. Programmers need them for hash table sizes, modular hashing, test cases for primality functions and toy RSA demonstrations. Puzzle makers use them in riddles and escape rooms.
Good to know
The output is generated with your browser's secure random source and never leaves your device. For serious cryptography use a dedicated library that works with much larger primes. To check numbers you already have, combine this page with the Random Integer Generator to compare primes with ordinary integers.
Frequently Asked Questions
How does the tool know a number is prime?
It uses the Miller–Rabin test with the first twelve prime bases (2 to 37). For every number below 3.3 × 10^24 that set of bases is proven to be deterministic, so every result for safe JavaScript integers is a certain prime, not a probable one.
Is every prime in the range equally likely?
Yes. For ranges up to two million numbers the tool lists all primes and picks among them uniformly. For larger ranges it draws random numbers and keeps only primes, which is also uniform across the primes in the range.
Can I use these primes for RSA keys?
No. Real cryptographic keys need primes of 1024 bits or more, generated inside a vetted crypto library. This tool goes up to about 9 × 10^15 and is meant for learning, puzzles and test data.
Why do I get an error for some ranges?
Some short ranges contain no primes at all, for example 24 to 28. You also get an error if 'No repeats' is on and you ask for more primes than the range contains.