RE: [PHP] Unique Identifier String
| From: | John W. Holmes | Date: | Mon, 11 Nov 2002 04:34:38 +0000 |
| Subject: | RE: [PHP] Unique Identifier String | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-123753@lists.php.net to get a copy of this message | ||
What if you create an array of all the letters and numbers, then shuffle
that array, implode it into a string and grab the first 24 characters?
It should be fairly random, but not guaranteed unique.
---John Holmes...
> -----Original Message-----
> From: @ Edwin [mailto:copperwalls@hotmail.com]
> Sent: Sunday, November 10, 2002 6:22 AM
> To: Sebastian A.
> Cc: php-general@lists.php.net
> Subject: Re: [PHP] Unique Identifier String
>
> Hello,
>
> "Sebastian A." <sebi@xinium.com> wrote:
>
> > I am currently working on a mySQL site administration system and I
need
> help
> > on figuring out how I can create a 24 digit letter/number unique
> identifier
> > string. I know that I can easily get a random number using a PHP
> function
> (I
> > can remember it off the top of my head) but I also need to create
random
> > letters and then insert them into the number. Here are the steps of
the
> > process:
> >
> > 1. Create a 12 digit random number using a PHP function
> > 2. Create 12 random letters
> > 3. Insert the letters into the number, or the other way around
> > Result: 1h5l79G05OP65kN61LPs1o6Z
> >
> >
> > Out of the steps above, I am not sure how to do 2 and 3 and I would
> greatly
> > appreciate it if someone could point out for me how to do them.
>
> This may not be the best way but you can do it this way:
> 1. Make sure that the number 1 above is in an array. Then,
> 2. Make an array of uppercase and lowercase letters, shuffle() them.
> 3. Get 12 from each. (i.e. by looping thru each and assigning it to
> another
> array, etc.)
> 4. array_merge() the two resulting arrays.
> 5. shuffle() again.
>
> Should work...
>
> - E
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php