nonexistentera Posted August 18, 2008 Share Posted August 18, 2008 Hello. I am wondering how I can get the script below to produce a list of random alphanumeric strings that are less that 10 characters in length and contain all possible combinations. Such as "a, b, c... aa,ab,ac" until it goes through the full list of available characters. <?PHP $length = 2; $complete = 10; $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; $charslength = strlen($chars); $randomstring = ''; mysql_connect("localhost","tylerper_root","tperroux") or die("No connection"); while ($t < $length) { while ($i < $complete) { $randomstring .= substr($chars, rand(0, $charslength - 1), 1); mysql_query(" INSERT INTO `tylerper_cookbook2`.`xl` ( `id` , `md5` ) VALUES ( '', '$randomstring' ); "); echo $randomstring. " <br> "; $i++; } $t++; } ?> It produces some what what I would like but not as repeatative for each string length. 0 01 018 0181 01817 01817T 01817TV 01817TVS 01817TVSN 01817TVSN5 It only does the length once then goes up, but I need it to do the length the number of times of how many characters there are eg. 26. and have it change instead of just adding another random letter/number. Any help is much appreciated. Thanks Quote Link to comment Share on other sites More sharing options...
JonnoTheDev Posted August 19, 2008 Share Posted August 19, 2008 I think your after permutations rather than combinations. Take a look at: http://www.php.happycodings.com/Algorithms/code21.html Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.