I'm using the following function to generate a random string:

function randstring($minasc = 32,$maxasc = 255,$minlength = 0,$maxlength = 0){
//If maximum length is lower than minimum length, return string representation of false
if($maxlength != 0 and $minlength != 0 and $minlength > $maxlength){
return '';
//Initialize $return
$return = '';
//Start infinite while loop, which will be exited with break;
//Add another random character to $return
$return = $return.chr(mt_rand($minasc,$maxasc));
//Break out of loop when it's time to
if((strlen($return) == $maxlength) or (mt_rand(1,2) == 2 and (strlen($return) >= $minlength or $minlength == 0) and (strlen($return) <= $maxlength or $maxlength == 0))){
//Return the value of $return
return $return;
But when I run it with:
and I check how many strings it generates before reaching a certain string, some strings take much longer than others. Is this just a problem with using pseudo-random numbers, or is there a better way to randomize this function?

The above message is encrypted with double rot13 encoding. Any unauthorized attempt to decrypt it will be prosecuted to the full extent of the law.

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

Reply via email to