Numbers

Random Prime Number Generator

Draw a random prime number from any range. Xrandom tests each candidate for primality on the fly and keeps redrawing until a genuine prime turns up.

Cryptographically secure Instant, in your browser Free, no sign-up

Generate

Your result will appear here

How the Random Prime Number Generator works

A prime number has exactly two divisors: 1 and itself. Rather than pre-listing every prime in a range, this tool draws a genuinely random candidate integer and tests it on the spot using trial division up to its square root — the same basic primality test taught in introductory number theory — repeating the draw whenever the candidate fails until enough unique primes are found.

This means the primes returned are a random sample of the primes within your range, not simply the first few found in order, since the candidate itself is drawn randomly before being tested.

How to use it

1
Set your rangeChoose a minimum (2 or higher) and maximum — wider ranges find primes faster since they're denser among small numbers.
2
Choose how manyDraw a single prime or several unique ones at once.
3
GenerateXrandom repeatedly draws a random candidate and tests it for primality with trial division until enough genuine primes are found.

Frequently asked questions

Why did it say no prime was found?

This happens if your range is extremely narrow and happens to contain no primes, or if the range is so large that random sampling took too long — try a wider or more reasonable range.

How large a range can I use?

Ranges up into the tens of millions work, though very large maximums make trial division noticeably slower per candidate.

Is this suitable for cryptographic key generation?

No — real cryptographic primes need hundreds of digits and probabilistic primality tests like Miller–Rabin; this tool is for education and casual use with everyday-sized numbers.