Monte Carlo Primality Testing
I’m going to take a stab at proposing a Monte Carlo algorithm for primality testing that will take a trivial amount of time. It’ll turn out to be a terrible algorithm in practice, so don’t try it at home! In fact, I’m going to call this method “Bad Primality Testing.” I’m only introducing it because it’ll make the “good” primality testing easier to understand.
Here is the Bad Primality Testing algorithm:
Instead of dividing number by all odd integers from 3 and up until the square root of number, we’ll divide number by a bunch of randomly chosen integers. If we choose, say, 100 random integers and divide number by them and always get a remainder, there’s a certain probability that number is prime.
This certainly ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access