Is there a built in function that can generate a random prime number between 2 given limits in C/C++?
I want a function that can generate a random prime number between 1 million and 1 billion
To find whether a larger number is prime or not, add all the digits in a number, if the sum is divisible by 3 it is not a prime number. Except 2 and 3, all the other prime numbers can be expressed in the general form as 6n + 1 or 6n - 1, where n is the natural number.
You can do this efficiently like so:
2 .. 17
, experiment for best results). If yes, go to 1;Also see this for a similar, a bit more complex, idea.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With