got this script... but it is not quite what I needed... that is why I am seeking help... This is the code: <?php function generateRandomString($length = 10) { $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $charactersLength = strlen($characters); $randomString = ''; for ($i = 0; $i < $length; $i++) { $randomString .= $characters[rand(0, $charactersLength - 1)]; } return $randomString; } // Echo the random string. // Optionally, you can give it a desired string length. <?php echo generateRandomString(); ?> ?> PHP: basically, I wanted this small php script to generate thousands of lines (~3000)... in this format: mytext/(the_random_string_here) mytext/(the_random_string_here) mytext/(the_random_string_here) mytext/(the_random_string_here) mytext/(the_random_string_here) up to the very end (~3000 lines) with each line have a random string... Thank you so much guys!
I think you've missed the point. @n00bl3t you just need to put a loop in there to run it the 3000 times. I've assumed you are trying to create some sort of link and I've put them into an unordered list. Use what you need but it should give you something to work with. function generateRandomString($length=10){ // everything in your existing function looks fine } for ($i = 0; $i < 3000; $i++){ $str = generateRandomString(); echo "<li><a href='/mytext/{$str}'>{$str}</a></li>"; } Code (markup):
Not to interrupt much, but here is your function's a little faster version: <?php function generateRandomString($length = 10) { srand(time()); $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; if ($length > strlen($characters)) $length = strlen($characters); $characters = str_shuffle($characters); return substr($characters,0,$length); } Code (markup): Stay well...
You can user this function for generate random string, function rand_code($len) { $min_lenght= 0; $max_lenght = 100; $bigL = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; $smallL = "abcdefghijklmnopqrstuvwxyz"; $number = "0123456789"; $bigB = str_shuffle($bigL); $smallS = str_shuffle($smallL); $numberS = str_shuffle($number); $subA = substr($bigB,0,5); $subB = substr($bigB,6,5); $subC = substr($bigB,10,5); $subD = substr($smallS,0,5); $subE = substr($smallS,6,5); $subF = substr($smallS,10,5); $subG = substr($numberS,0,5); $subH = substr($numberS,6,5); $subI = substr($numberS,10,5); $RandCode1 = str_shuffle($subA.$subD.$subB.$subF.$subC.$subE); $RandCode2 = str_shuffle($RandCode1); $RandCode = $RandCode1.$RandCode2; if ($len>$min_lenght && $len<$max_lenght) { $CodeEX = substr($RandCode,0,$len); } else { $CodeEX = $RandCode; } return $CodeEX; } echo rand_code(10); PHP:
One more version accommodating longest possible strings /** * accommodates long string creation */ function generate_random_string($length = 10) { $buf = implode('', array_merge(range('0','9'), range('a','z'), range('A','Z'))); if ($length > strlen($buf)) $buf = str_repeat($buf, ceil($length / strlen($buf))); return str_shuffle(substr($buf, 0, $length)); } #Try longer string print generate_random_string(1024); PHP: