So, I have been playing around with prime numbers, I have installed gmp and gmpy2
gmpy2 has a function gmpy2.is_prime for primality testing (non deterministic) which uses the Miller-Rabin primality test.
Now to test the speed of gmpy2.is_prime I typed some random digits '1245268798719487981976914598618498569816481948' and added a '3' to the end so that the number is not even. It took it milliseconds to get the result and to my surprise,
In [18]: gmpy2.is_prime(12452687987194879819769145986184985698164819483)
Out[18]: True
What? really? the number I randomly typed is a prime?
To make sure is_prime wasn't returning true for every other number I added a few digits and expectedly
In [25]: gmpy2.is_prime(124526879871948798197691459861849856981648139483)
Out[25]: False
In [26]: gmpy2.is_prime(12452687987194879819769145986555184985698164819483)
Out[26]: False
I was blown away, but now, I am curious. What is the probability of this happening?
More specifically, What is the probability that a randomly selected odd 47 digit number passes Miller-Rabin primality test?
Did I just get really really lucky?
According to Prime number theorem there are approximately $$10^{47}/\ln(10^{47}) - 10^{46}/\ln(10^{46}) = 8.296\cdot10^{44}$$ 47-digit primes and $$9\cdot10^{46}/2$$ odd 47-digit numbers. So the probability is approximately $8.296\cdot10^{44}/4.5\cdot10^{46} = 0.018$.
Without numbers with 5 as last digit the probability is approximately $8.296\cdot10^{44}/3.6\cdot10^{46} = 0.023$.
Edit:
The values with the somewhat better approximation $1/\ln(x)$ for the probability that a random integer not greater than $x$ is prime are
$0.01868$ for odd number in the given range and
$0.02335$ for odd numbers not ending with 5.