Hi all,

I'm having a problem with the rand function. I use the function below:

function gen_short_primary_key_value( $maxlength = 5 )
    $mt = split( ' ', microtime(), 2 );
    $foo = (double) ($mt[0] + $mt[1]) * 10000;
    $md5 = strtoupper( md5( $foo ) );
    for ( $j = 0; $j < $maxlength; $j++ )
        $key .= $md5[ rand( 0, strlen( $md5 ) ) ];
    return $key;

This function works nice on a Windows machine with PHP 4.2.2 (commandline)
and also on a Solaris 7 machine with PHP 4.2.2 (also commandline). But when
I implement this function into a website and call it, the rand() function
will always returns "0" as the answer, making my primary key values always
like "00000", "11111", "AAAAA" and so on.

The nice thing about this function is, is that's it's really random ;-))
I've looped it (on commandline) trough 100.000 iterations, and not one value
was the same! I need it's purpose because I need a random value which is not
to long.

Hope you guys can help me out here!

Grtz Erwin

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

Reply via email to