简体   繁体   中英

Could not generate 6 digit random number including date time using PHP

I need one help . I need to generate random number including date and time using PHP. I am explaining my code below.

$random=generateRandom();
echo $random;
function generateRandom() {
    $result = base_convert((float) rand() / (float) getrandmax() * round(microtime(true) * 1000),6, 36);
    return $result;
}

The above function giving the 3 digit output. Here i need to generate up to 6 digit. Please help me.

Here it is with microtime :

$random=generateRandom();
echo $random;
function generateRandom() {
    $numbers = str_split((string)(int)microtime(true));
    shuffle($numbers);
    $rand = '';
    foreach (array_rand($numbers, 6) as $k) $rand .= $numbers[$k];
    return $rand;
}

Conversion are here to eliminated the dot character.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM