Forklaring på: mt_srand((double)microtime()*1000000);
HejsaJeg har fundet følgene function på nettet, nen der er en ting jeg ikke forstår.
Dette fatter jeg ikke:
---
// Seed the random number generator with the microtime stamp
// (current UNIX timestamp, but in microseconds)
mt_srand((double)microtime()*1000000);
---
En der gider at forklare hvordan ovenstående fungere og gør ?
Her er hele functionen:
--------------
// A function to generate random alphanumeric passwords in PHP
// It expects to be passed a desired password length, but it
// none is passed the default is set to 10 (you can change this)
function generate_password($length = 10) {
// This variable contains the list of allowable characters
// for the password. Note that the number 0 and the letter
// 'O' have been removed to avoid confusion between the two.
// The same is true of 'I' and 1
$allowable_characters = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
// We see how many characters are in the allowable list
$ps_len = strlen($allowable_characters);
// Seed the random number generator with the microtime stamp
// (current UNIX timestamp, but in microseconds)
mt_srand((double)microtime()*1000000);
// Declare the password as a blank string.
$pass = "";
// Loop the number of times specified by $length
for($i = 0; $i < $length; $i++) {
// Each iteration, pick a random character from the
// allowable string and append it to the password.
$pass .= $allowable_characters[mt_rand(0,$ps_len-1)];
} // End for
// Retun the password we've selected
return $pass;
}
--------------
:)
