mardi 23 août 2016

PHP generate random number without start with 0 or 00

i've create a function to generate a random number but i want to remove 0 from this number and i want to start this number with any number different to 0.

My Code:

function createRandomNumber() {
    $chars = "07659242202345640248765924276987346549823433445754767659242599";
    srand ( ( double ) microtime () * 1000000 );
    $i = 0;
    $pass = '';
    while ( $i <= 7 ) {
          $num = rand () % 33;      
          $tmp = substr ( $chars, $num, 1 );
          $pass = $pass . $tmp;
          $i ++;
    }
    return $pass;
}




Aucun commentaire:

Enregistrer un commentaire