I want to create a random number not containing an '0' Why? A user may easily confuse a 0 (numerical) with an O (letter).

mt_rand (11, 99) gets a random number between 11 and 99, but that includes 20, 30, 40, 50, 60, 70, 80, and 90.

I'm not sure how to proceed. Any suggestions?

Thanks.

    here are a couple of ideas...

    mt_srand ((double) microtime() * 1000000);
    $num = mt_rand (11, 99);
    while (ereg("0",$num)) {
    mt_srand ((double) microtime() * 1000000);
    $num = mt_rand (11, 99);
    }
    

    or...

    mt_srand ((double) microtime() * 1000000);
    $num = mt_rand (11, 99);
    if (ereg("0",$num)) {
    mt_srand ((double) microtime() * 1000000);
    $ones = mt_rand (1, 9);
    $num = str_replace("0",$ones,$num);
    }
    

    or simply...

    mt_srand ((double) microtime() * 1000000);
    $num = mt_rand(1,9) . mt_rand(1,9);
    

      mt_rand(1,9) . mt_rand(1,9);

      Ah, of course. Thanks!

        Write a Reply...