DEV Community

Cover image for Miller Robin Primality Test
Remon Hasan
Remon Hasan

Posted on

1

Miller Robin Primality Test

Similar to Fermat primality test, Miller-Rabin primality test could only determine if a number is a probable prime.

It is based on a basic principle where if , but , then is composite.

The algorithm in simple steps can be written as,

Given a number () for which primality is to be tested,
Step 1: Find
Step 2: Choose in range
Step 3: Compute . If is , can be prime.
Step 4: Compute . If , is composite.
If , is prime.
Step 5: Repeat Step 4 for times.
Step 6: If neither or appeared for , is composite.

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Best practices for optimal infrastructure performance with Magento

Running a Magento store? Struggling with performance bottlenecks? Join us and get actionable insights and real-world strategies to keep your store fast and reliable.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️