adam84 Posted March 17, 2007 Share Posted March 17, 2007 I need 'x' amount of random numbers, when i use the code below I always get the same results. Is there a better or different way of doing it? for( $i = 0; $i 5; $i++){ $time = time(); $length = 10; srand(date("s")); $possible_charactors = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; $ticketNum = ''; while(strlen($ticketNum )<$length) $ticketNum .= substr($possible_charactors, rand()%(strlen($possible_charactors)),1); echo $ticketNum. "<BR>"; } Link to comment https://forums.phpfreaks.com/topic/43149-random-number/ Share on other sites More sharing options...
kenrbnsn Posted March 17, 2007 Share Posted March 17, 2007 You dont need to initialize with the srand() function anymore. Remove that line. You dont' need this line: <?php $time = time(); ?> either. Ken Link to comment https://forums.phpfreaks.com/topic/43149-random-number/#findComment-209551 Share on other sites More sharing options...
shaunrigby Posted March 17, 2007 Share Posted March 17, 2007 use rand(min no,max no) Link to comment https://forums.phpfreaks.com/topic/43149-random-number/#findComment-209560 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.