Leandro Junes

Probable Prime Generator

Draws random odd integers of the chosen size, then tests them with the site's shared primality pipeline. Large searches run in a Web Worker.

Inputs

Integer from 2 to 4096.

Approximate: several bit lengths share the same digit count. Bit length is used internally, and editing either field updates the other.

Try

Result

—

Probable prime

—

Bit length
—
Decimal digits
—
Candidates tested
—
Additional MR rounds
—
Generation time
—

How it works

—
  1. Draw a cryptographically random candidate of exactly the requested bit length, using crypto.getRandomValues() — never Math.random().
  2. Force the top bit to 1, so the candidate has exactly that many bits, and the bottom bit to 1, so it's odd.
  3. The shared test rejects candidates divisible by primes through 1000 and checks for exact squares.
  4. Below the documented bound it uses deterministic Miller–Rabin. Larger candidates use Baillie–PSW followed by 12 random Miller–Rabin rounds.
  5. A failed candidate is discarded; the first one that passes is returned.

For arbitrary-size results, passing these tests is strong evidence of primality, not a general mathematical proof.