Re: Sequential Random Character Generator

From: Date: Thu, 26 Feb 2004 01:05:36 +0000
Subject: Re: Sequential Random Character Generator
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-178896@lists.php.net to get a copy of this message
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" <milesthompson@ns.sympatico.ca> wrote in message news:5.2.0.9.0.20040225124542.01e3cce8@pop1.ns.sympatico.ca... > At 11:25 AM 2/25/2004 -0500, list@pfohlsolutions.com 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 >

« previous php.general (#178896) next »