Random Prime Number Generator
Draw random prime numbers from any range you set, up to ten million.
A prime number is a whole number greater than 1 that has exactly two divisors: 1 and itself. So 7 is prime (nothing divides it but 1 and 7), 9 is not (3 divides it), and 1 is neither prime nor composite — it sits in its own category, which surprises people the first time they hear it. This generator lets you set a range, from 2 up to 10,000,000, and draws primes from inside it: one for a quick prompt, or up to fifty at a time for exercises, test data and games.
Set a range and draw primes from it. The tool finds every prime in the range first, then picks from that list — so each prime has exactly the same chance.
Want ordinary whole numbers instead, prime or not? Use the Random Number Generator. Checking a divisor or working out a square root afterwards is a job for the Scientific Calculator.
Quick answers
How does a random prime number generator work?
This one first finds every prime inside your range with a sieve, then draws from that complete list using crypto.getRandomValues with rejection sampling, so each prime in the range is equally likely to be picked.
Building the full list first is what keeps the draw fair. If a tool instead rolled random integers and kept the first one that passed a prime test, primes sitting after long runs of composite numbers would be picked more often than primes in crowded stretches. Drawing uniformly from the finished list removes that skew entirely.
How many primes are there in my range?
The tool tells you after every draw — it counts the primes in the range as part of finding them. As anchors: 25 primes below 100, 168 below 1,000 and 78,498 below 1,000,000.
Mathematicians write that count as pi(x), the number of primes up to x. It grows steadily but ever more slowly: primes get rarer as numbers get bigger, which is why a range near ten million holds noticeably fewer primes per thousand numbers than a range near a hundred does — yet any range of decent width still holds plenty to draw from.
What happens if I ask for more unique primes than the range holds?
You get all of them, shuffled, with a note saying the draw was shortened. The tool never repeats a prime to fill a quota while the no-repeats option is on.
Small ranges run dry fast. Between 90 and 100 there is exactly one prime, 97, so asking for five unique primes there returns just 97 and explains why. Widen the range, lower the count, or switch the unique option off if repeats are acceptable for what you are doing.
How to use
- Set the lowest and highest numbers for your range — the minimum can be as low as 2 and the maximum as high as 10,000,000.
- Choose how many primes to draw, from 1 to 50, and tick Unique if no prime may appear twice.
- Press Generate primes. The results appear in large type, with a line underneath telling you how many primes exist in the whole range.
- Press the button again for a fresh draw, or widen the range if you need more unique primes than the current one holds.
About this tool
The tool works in two honest steps. First it finds every prime in your range, using a sieve — the old Eratosthenes trick of crossing out multiples — so the list it draws from is complete, not sampled or guessed. Then it draws from that list uniformly, using the browser’s cryptographic random source with rejection sampling. Uniform matters: every prime in the range has exactly the same chance of being picked, whether it is 3 or 9,999,937. Picking a random integer and testing it until a prime turns up would quietly favour primes that sit after long gaps; drawing from the complete list does not.
A few landmarks help you choose a range. There are 25 primes below 100, 168 below 1,000, and 78,498 below 1,000,000 — that last count is written pi(1,000,000) = 78,498 by mathematicians, where pi here is the prime-counting function, nothing to do with circles. Primes thin out as numbers grow, but they never run out: Euclid proved more than two thousand years ago that the list is endless. If you ask for more unique primes than your range contains — say ten different primes between 90 and 100, where only 97 qualifies — the tool returns all of them and tells you, rather than repeating one and pretending.
Everything runs in this page, on your device. The ranges you type and the primes you draw are never uploaded, sent anywhere or saved, and closing the tab clears them. For ordinary whole numbers rather than primes, the Random Number Generator linked under the tool is the plainer option, and the Scientific Calculator covers the follow-up arithmetic — testing a divisor, say, or working out a square root.
How many primes are there? The prime-counting function pi(x)
| Up to | Primes below it, pi(x) |
|---|---|
| 100 | 25 |
| 1,000 | 168 |
| 10,000 | 1,229 |
| 100,000 | 9,592 |
| 1,000,000 | 78,498 |
| 10,000,000 | 664,579 |
Frequently asked questions
Is 1 a prime number?
No. A prime must have exactly two divisors, and 1 has only one — itself. It is classed as a unit, neither prime nor composite. The smallest prime is 2, which is also the only even prime: every other even number is divisible by 2 and so is composite.
Are the draws really uniform — is every prime equally likely?
Yes. The tool builds the complete list of primes in your range first, then picks positions in that list with crypto.getRandomValues and rejection sampling, which removes the small rounding bias a plain modulo would introduce. Position in the list is all that matters, so every prime has the same chance.
What is the largest range I can use?
The maximum is 10,000,000 and the minimum is 2. Within that, any width works — the sieve that finds the primes handles a full ten-million range comfortably on a phone. Ranges are capped there to keep the page instant; for classroom and test-data purposes it is far more than anyone needs.
How does the tool decide whether a number is prime?
It does not test numbers one by one in the way you might by hand. It sieves the range: starting from 2, it crosses out every multiple of each prime it finds, and whatever is left standing is prime. That is deterministic — the same range always produces the same complete list — and only the draw from the list is random.
Can the same prime come up twice?
Only if you leave the Unique box unticked. With Unique on, the draw is made without replacement, like dealing from a deck, so each prime can appear at most once — and if you ask for more than the range holds, you get all of them once each, with a note.
Is anything I generate stored or sent anywhere?
No. The sieve and the draw both run in your browser tab. Nothing is uploaded, logged or kept, and refreshing or closing the page wipes the result.
More free tools
Scientific Calculator
Full scientific calculator: trig, logs, powers, factorial. Free, private, runs in your browser.
Random Number Generator
Pick random numbers in any range, with no repeats option.
QR Code Generator
Turn any link or text into a scannable QR code in seconds.
Random Password Generator
Create strong, random passwords — generated on your device only.
Coin Flip
Heads or tails — settle it fairly.
Dice Roller
Roll any dice — d4 to d100, multiples included.