Here's a function I made for random string generation:

http://www.ircphp.com/users/imho/?file=function.randstr.php

randstr(len, seeds);

so, echo randstr(10, "abc123"); would result in a 10 letter string made up
of a,b,c,1,2,3

Hoep this helps.


"Miles Thompson" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> At 11:25 AM 2/25/2004 -0500, [EMAIL PROTECTED] wrote:
> >I'm trying to create a PHP sequential random character generator that
will
> >output to a file database of some sort. The randomization needs to be
> >using both capital letters and numbers. I need to output like 2 million
> >records. Can someone point me in the right direction on how to do this?
> >
> >I'm also looking to to this without letters as well.
> >
> >Thanks in advance,
> >Steve
>
> First of all, have you tried it? Pseudo-coded it? Here's one approach:
>
> Check the decimal ranges of the ASCII table for the character set(s) you
> want. That will determine the limits of the random numbers you will
accept.
>
> Start a loop, the number of iterations equal to the length of the string
> you want, calling rand() with the decimal limits you will accept.
>
> Convert the output of rand() to a character using chr() and store it in
> your string.
>
> Loop until the string is filled.
>
> Search your database for the value of the string. If it's not found, which
> assures you of it's uniqueness, execute an INSERT or UPDATE, whichever is
> appropriate for what you're doing. (Alternately append to the end of a
file
> if you are using a text file if that's what you are doing, but if you want
> to check for uniqueness you will have to read the file each time, v.
slow.)
>
> Clear the string and repeat. (Actually you could just overwrite the
string.)
>
> Do the above 2 million times. It's amazingly fast.
>
> May we ask why you are doing this?
>
> Regards - Miles Thompson
>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to