needs_upgrade Posted April 16, 2013 Share Posted April 16, 2013 Hello guys. How can i make 50,000 unique string characters? What i have in mind is to md5() numbers 1-50,000. But my client wants those strings to be 10 characters in length only. Where should i start? Thanks guys! Link to comment https://forums.phpfreaks.com/topic/277002-generate-unique-strings-of-characters/ Share on other sites More sharing options...
Jessica Posted April 16, 2013 Share Posted April 16, 2013 The numbers 1 through 10,000 are already unique Link to comment https://forums.phpfreaks.com/topic/277002-generate-unique-strings-of-characters/#findComment-1425043 Share on other sites More sharing options...
Jessica Posted April 16, 2013 Share Posted April 16, 2013 Er, 50,000. Link to comment https://forums.phpfreaks.com/topic/277002-generate-unique-strings-of-characters/#findComment-1425044 Share on other sites More sharing options...
jugesh Posted April 20, 2013 Share Posted April 20, 2013 Here I am sharing my code which I have written to generate unique nos. Please go through it hope It will help u out. function uniqueID($table){// The length we want the unique reference number to be$unique_ref_length = 10;// A true/false variable that lets us know if we've// found a unique reference number or not$unique_ref_found = false;// Define possible characters.// Notice how characters that may be confused such// as the letter 'O' and the number zero don't exist $possible_chars = "23456789abcdefghijklmanopqrstuvwxyz";// Until we find a unique reference, keep generating new oneswhile (!$unique_ref_found) { // Start with a blank reference number $unique_ref = ""; // Set up a counter to keep track of how many characters have // currently been added $i = 0; // Add random characters from $possible_chars to $unique_ref // until $unique_ref_length is reached while ($i < $unique_ref_length) { // Pick a random character from the $possible_chars list $char = substr($possible_chars, mt_rand(0, strlen($possible_chars)-1), 1); $unique_ref .= $char; $i++; } $unique_ref = $unique_ref; // Our new unique reference number is generated. // Lets check if it exists or not $query = "SELECT `CommonID` FROM ".$table." WHERE `CommonID`='".$unique_ref."'"; $result = mysql_query($query) or die(mysql_error().' '.$query); if (mysql_num_rows($result)==0) { // We've found a unique number. Lets set the $unique_ref_found // variable to true and exit the while loop $unique_ref_found = true; }}return $unique_ref;} Link to comment https://forums.phpfreaks.com/topic/277002-generate-unique-strings-of-characters/#findComment-1425913 Share on other sites More sharing options...
annaharris Posted May 6, 2013 Share Posted May 6, 2013 Try this code: <?php $i = 1; while ($i <= 50000) { echo(rand(1000000000,9999999999)); $i++; /* the printed value would be $i before the increment (post-increment) */ } Link to comment https://forums.phpfreaks.com/topic/277002-generate-unique-strings-of-characters/#findComment-1428573 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.