I'm searching for an efficient way to create thousands of unique random numbers. I would like them to be either all numeric, or a mix of numbers and letters. I would also like to keep the character length around 6 to 10 characters. Does anybody have a good idea?
I may have figured out the answer to my own question. http://www.codewalkers.com/c/a/Miscellaneous-Code/Multiple-Unique-Random-Numbers/
<?php function CreateRandomString($instances,$min_length,$max_length) { $chars = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQUSTUVWXYZ"; # srand((double)microtime()*1000000); # seed not needed since => php 4.2.0 $strings = Array(); for ($inst=0;$inst<=($instances-1);$inst++) { $i = 0; $pass = '' ; $randlength = rand($min_length,$max_length); while ($i <= $randlength) { $num = rand() % 33; $tmp = substr($chars, $num, 1); $pass = $pass . $tmp; $i++; } $strings[$inst] = $pass; } return $strings; } # # test it out # print_r(CreateRandomString(1000,6,10)); # # How to use it: # $instances: nubmer of random strings you want to create. # $min_length: minimum string length. # $max_length: maximum string length. # $chars: the charactor database to pick from at random ?> PHP: