1

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.

  • 3
    Possible duplicate of [Generate random 5 characters string](http://stackoverflow.com/questions/5438760/generate-random-5-characters-string) – bansi Dec 17 '16 at 06:34

1 Answers1

0

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.

Alexandre Tranchant
  • 4,426
  • 4
  • 43
  • 70