Random Prime Generator
Generate random prime numbers within a custom range with adjustable count
Grab a handful of random primes between any two numbers you pick — set the minimum, maximum, and count, then hit Generate. The tool sieves every prime in your range first, so each pick is guaranteed prime and the selection is actually random, not pseudo-random guesswork. And everything runs in your browser. Nothing gets uploaded.
How It Works
The tool runs an optimized Sieve of Eratosthenes to find every prime in your min–max window. Then it uses crypto.getRandomValues()—the same API browsers use for secure key generation—to randomly pick however many primes you asked for. The result is sorted ascending and ready to copy or download.
Examples
Picking Primes for a Hash Table Test
You’re benchmarking hash table sizes and need 5 primes between 100 and 500 to use as bucket counts.
Count: 5
Min: 100
Max: 500
107, 251, 313, 419, 487
Generating a Single Large Prime
Need one big prime around the 90,000 mark for an RSA demo in class. Just set count to 1 and widen the range.
Count: 1
Min: 80000
Max: 100000
91291
Small Primes for a Kids’ Math Worksheet
A teacher creating a worksheet on prime numbers grabs 10 random primes under 50 so students can circle them in a number grid.
Count: 10
Min: 2
Max: 50
2, 5, 7, 11, 17, 23, 29, 37, 41, 47
Who Uses This
Quick prime lists for hash functions, load testing, or seeding algorithms without writing a sieve every time.
Grab sample primes for number theory homework, cryptography labs, or discrete math problem sets.
Generate random primes for quizzes, worksheets, and classroom exercises without reusing the same examples.
Pull primes in specific ranges for testing key generation routines or protocol simulations.
Common Mistakes
2 is the smallest prime. If you enter 0 or 1 as your minimum, the tool adjusts to 2 automatically—but your effective range shrinks. Start at 2 or higher.
There are only 25 primes below 100. Ask for 30 primes between 2 and 100, and you’ll get an error. Widen the range or lower the count.
The sieve has to check every number up to your max. A max of 10 million is fine. 100 million will take a few seconds and use real memory. Keep it reasonable or your browser tab will struggle.
Technical Details
- Processing: 100% client-side JavaScript
- Algorithm: Sieve of Eratosthenes + crypto.getRandomValues()
- Max Range: Up to 10,000,000 (higher values possible but slower)
- Browser Support: Chrome, Firefox, Safari, Edge
- Output Formats: Comma, newline, space, or tab delimited
Frequently Asked Questions
Are the generated primes truly random?
Yes. The tool uses crypto.getRandomValues(), which is the browser’s cryptographically secure random number generator. The primes themselves come from a deterministic sieve, but which ones get picked is genuinely random.
What is the Sieve of Eratosthenes?
It’s an ancient algorithm for finding all primes up to a given limit. You start with a list of numbers and cross off multiples of each prime, starting with 2. Whatever’s left uncrossed is prime. It is one of the fastest ways to generate primes in bulk.
Can I generate primes larger than 10 million?
Technically yes—the tool doesn’t hard-block it. But sieving past 10 million takes noticeable time and memory in the browser. If you need very large primes (hundreds of digits), you’d want a probabilistic test like Miller-Rabin instead of a sieve.
Is this safe to use for cryptographic key generation?
For learning and prototyping, sure. For production cryptography, no. Real key generation needs primes hundreds of digits long with specific mathematical properties. This tool caps out well before that range. Use a proper crypto library for anything that matters.
Does this tool store or share my generated numbers?
No. The entire process runs in your browser. Nothing is uploaded, logged, or sent to any server. Refresh the page and the numbers are gone. Your data stays yours.