Jump to content

[SOLVED] Random Number Issue


adam84

Recommended Posts


function gen_number( $length ){
$time = time();
srand(date("s")); 
$possible_charactors = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 
$code = ""; 
while(strlen($code)<$length)
    $code .= substr($possible_charactors, rand()%(strlen($possible_charactors)),1);
return $code;
}

function temp(){
 for($i = 0; $i < 5; $i++)
    echo  gen_number( 5 ) . "<BR>";
}

 

I keep getting the same number all 5 times??!?!?!??!?! what should i do... thanks

Link to comment
https://forums.phpfreaks.com/topic/85127-solved-random-number-issue/
Share on other sites

Try:

<?php
function gen_number( $length, $rand ){
$time = time();
srand(date("s")); 
$possible_charactors = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 
$code = ""; 
while(strlen($code)<$length)
     $code .= substr($possible_charactors, $rand%(strlen($possible_charactors)),1);
return $code;
}

function temp(){
  for($i = 0; $i < 5; $i++)
     echo  gen_number( 5 , rand() ) . "<BR>";
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.