Well, here's an untested script off the top of my head:

function random_string($Ncharacters) {
   static $CharList = '0123456789abcdefghijklmnopqrstuvwxyz';
   $String = '';
   $Max = strlen($CharList)-1;
   for ($i=0; $<$Ncharacters; $i++) {
      $String .= $CharList{rand(0, $Max)};
   }
   return $String;
}

For php < 4.2.0, you'll need to seed the random number generator first; see

http://www.php.net/rand

You could probably also make something up using rand in conjunction with ord():

http://www.php.net/ord

Also see:

http://www.php.net/manual/en/language.types.string.php#language.types.string.parsing

-steve

At 04:32 PM 11/10/03, Jason Williard wrote:
I would like to have a script that randomly generates alpha-numeric
characters.  Does anyone know of any scripts that can do this or perhaps
the basic code to generate random characters?

Thank You,
Jason Williard

+------------------------------------------------------------------------+ | Steve Edberg [EMAIL PROTECTED] | | Database/Programming/SysAdmin (530)754-9127 | | University of California, Davis http://pgfsun.ucdavis.edu/ | +---------------------- Gort, Klaatu barada nikto! ----------------------+

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



Reply via email to