Hello again.

        I have the following function that generates a prime number of x
bits. It seems to work but i am just trying to see if i can make it any
faster as generateing 1024 bit prime can take a while. so i thoought i
would ask here to see if anybody has any ideas or suggestions.

        The function is as follows:


function generate_prime ($bits) {
    for($i=$bits; $i>=0; $i--){
        gmp_setbit($number, $i, $rand);
        $number=gmp_add($number, 1);
    if(strlen(gmp_strval($number, 2))!=$bits){
        return (string)gmp_strval($number);

At the moment im generating a random number of the required length and
then +1ing it untill it is a prime. I suppose i really want to know if
their is some way of knowing how close you are to a possiable prime so
that if the random number is too far away then it could call itself again
and try a different random start location.

I look forward to any ideas that you might have.


William Bailey.

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to