Re: Random Character Generator

From: Date: Tue, 11 Nov 2003 01:07:26 +0000
Subject: Re: Random Character Generator
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-169115@lists.php.net to get a copy of this message
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                                      sbedberg@ucdavis.edu |
| Database/Programming/SysAdmin                            (530)754-9127 |
| University of California, Davis             http://pgfsun.ucdavis.edu/ |
+---------------------- Gort, Klaatu barada nikto! ----------------------+

« previous php.general (#169115) next »