AndieB Posted October 29, 2007 Share Posted October 29, 2007 Hi all gurus! I am off trying to see if I can create a ticket reservation system, where a visitor should be able to reserve tickets and get a randomized unique alphanumeric string in uppercase letters with a total of 8 characters. I do not know how to create a script that randomizes letters, from A-Z, and puts it into a string only 8 characters long. To compare it with already stored "randomized" in a database, I guess it is only to do a search in the database. Anyone who has a good advice or script on how to generate what I would like to achieve? Example: GUTIIKLE YYTESVOP PUERBHGA I guess you all know what I am after. Thankful for any kind of help! Sincerely, Andreas Link to comment https://forums.phpfreaks.com/topic/75254-solved-generate-randomized-alphanumeric-string/ Share on other sites More sharing options...
micah1701 Posted October 29, 2007 Share Posted October 29, 2007 first make an array of all the letters/numbers you want to use. (if people will be typeing this string at somepoint I like to leave out the letter O and the number zero as well as the number 1 and letters like I and lowercase L) then do a loop with 8 passes. each time through the loop use rand() to pick a character out of your array and ad it to a string. Link to comment https://forums.phpfreaks.com/topic/75254-solved-generate-randomized-alphanumeric-string/#findComment-380618 Share on other sites More sharing options...
effigy Posted October 29, 2007 Share Posted October 29, 2007 <pre> <?php srand(time()); $pool = array_merge( range('a', 'z'), range('A', 'Z'), range(0, 9) ); $pool_size = count($pool) - 1; for ($i = 0; $i < 8; $i++) { echo $pool[rand(0, $pool_size)]; } ?> </pre> Link to comment https://forums.phpfreaks.com/topic/75254-solved-generate-randomized-alphanumeric-string/#findComment-380627 Share on other sites More sharing options...
AndieB Posted April 28, 2008 Author Share Posted April 28, 2008 <pre> <?php srand(time()); $pool = array_merge( range('a', 'z'), range('A', 'Z'), range(0, 9) ); $pool_size = count($pool) - 1; for ($i = 0; $i < 8; $i++) { echo $pool[rand(0, $pool_size)]; } ?> </pre> Thank you very much!! This solved it! Link to comment https://forums.phpfreaks.com/topic/75254-solved-generate-randomized-alphanumeric-string/#findComment-528736 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.