Ryahn Posted June 14, 2010 Share Posted June 14, 2010 I have a mailer script that will be mailing grabbing info from a database. In that database there is an ID field, but I have it right now only doing AutoNumber but I want to be able to make random 6 digit ID numbers to that way when a form is submitted, it will send that user an ID and their password. I dont know how to do this, so this is why I am asking. Link to comment https://forums.phpfreaks.com/topic/204683-create-random-ids/ Share on other sites More sharing options...
Catfish Posted June 14, 2010 Share Posted June 14, 2010 http://snipplr.com/view/1027/generate-random-string/ see comments on page for any limitations of the function. Link to comment https://forums.phpfreaks.com/topic/204683-create-random-ids/#findComment-1071635 Share on other sites More sharing options...
Ryahn Posted June 14, 2010 Author Share Posted June 14, 2010 Thanks for that. I ended just looking around and found this. function generate_numbers($min, $max, $anz) { $array = range($min, $max); srand ((double)microtime()*1000000); for($x = 0; $x < $anz; $x++) { $i = rand(1, count($array))-1; $erg[] = $array[$i]; array_splice($array, $i, 1); } return $erg; } // 5 eindeutige Zahlen im Bereich von 1 bis 100 ermitteln $zufalls_array = generate_numbers(1, 100, 5); echo join("; ", $zufalls_array); which I then did a little tweak function generate_numbers($min, $max, $anz) { $array = range($min, $max); srand ((double)microtime()*10000); for($x = 0; $x < $anz; $x++) { $i = rand(1, count($array))-1; $erg[] = $array[$i]; array_splice($array, $i, 1); } return $erg; } // 5 eindeutige Zahlen im Bereich von 1 bis 100 ermitteln $zufalls_array = generate_numbers(1, 100, 3); $code = join("", $zufalls_array); Now the $code just gets inserted into the ID field of the database and thats it. Thanks for it. Link to comment https://forums.phpfreaks.com/topic/204683-create-random-ids/#findComment-1071647 Share on other sites More sharing options...
phpchamps Posted June 14, 2010 Share Posted June 14, 2010 y didnt you used uniq_id function of php??? Link to comment https://forums.phpfreaks.com/topic/204683-create-random-ids/#findComment-1071761 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.