Skip to content

Instantly share code, notes, and snippets.

@petk
Last active August 29, 2015 14:05
Show Gist options
  • Save petk/ea898e58dc620bc7f40c to your computer and use it in GitHub Desktop.
Save petk/ea898e58dc620bc7f40c to your computer and use it in GitHub Desktop.
<?php
function generateRandomNumber($length)
{
list($usec, $sec) = explode(' ', microtime());
srand((float) $sec + ((float) $usec * 100000));
$validchars = "0123456789";
$number = "";
$counter = 0;
while ($counter < $length) {
$actChar = substr($validchars, rand(0, strlen($validchars)-1), 1);
$number .= $actChar;
$counter++;
}
return (int) $number;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment