Author Topic: [SOLVED] Generate Randomized Alphanumeric String  (Read 628 times)

0 Members and 1 Guest are viewing this topic.

Offline AndieBTopic starter

  • Enthusiast
  • Posts: 165
  • Gender: Male
  • "You create your own reality..."
    • View Profile
    • http://bodin.acnrep.com
[SOLVED] Generate Randomized Alphanumeric String
« on: October 29, 2007, 03:43:13 PM »
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
" Start by looking in the mirror before pointing the finger outwards... "
" Nothing can be, until it has passed your mind... "

Offline micah1701

  • Devotee
  • Posts: 946
  • Gender: Male
    • View Profile
    • I'm on Google+
Re: Generate Randomized Alphanumeric String
« Reply #1 on: October 29, 2007, 03:45:19 PM »
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.
« Last Edit: October 29, 2007, 03:46:44 PM by micah1701 »
"Confidence in the face of risk."

Offline effigy

  • Staff Alumni
  • Freak!
  • *
  • Posts: 7,301
  • Gender: Male
  • We must be the change we wish to see in the world.
    • View Profile
Re: Generate Randomized Alphanumeric String
« Reply #2 on: October 29, 2007, 03:56:49 PM »
Code: [Select]
<pre>
<?php 
srand(time());
$pool array_merge(
range('a''z'),
range('A''Z'),
range(09)
);
$pool_size count($pool) - 1;
for ($i 0$i 8$i++) {
echo $pool[rand(0$pool_size)];
}
?>

</pre>
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

Offline AndieBTopic starter

  • Enthusiast
  • Posts: 165
  • Gender: Male
  • "You create your own reality..."
    • View Profile
    • http://bodin.acnrep.com
Re: Generate Randomized Alphanumeric String
« Reply #3 on: April 28, 2008, 03:21:50 AM »
Code: [Select]
<pre>
<?php 
srand(time());
$pool array_merge(
range('a''z'),
range('A''Z'),
range(09)
);
$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!
" Start by looking in the mirror before pointing the finger outwards... "
" Nothing can be, until it has passed your mind... "