I put together the following function to give me a password consisting of random 
letters and numbers.  It should be fairly clear as to how you'd need to tweak it to 
just give you the characters you'd need interspersed with spaces.

Hope this helps - I also hope anybody else is fairly gentle with their criticisms and 
pointers to whatever is wrong with the script - this is the first time I've ventured 
to include something like this in a response to an email on the list :-(


   function get_password()
   {
      // Create the password variable as an array
      $temp_password = array();
      // Create an array of the letters of the alphabet
      $letters = array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k",
                       "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v",
                       "w", "x", "y", "z");
      // Get the first three alpha characters of the password
      for($row = 0; $row < 3; $row ++)
      {
        srand ((double) microtime() * 1000000);
        $rand_number = rand(0, 25);
        $letter = $letters[$rand_number];
        array_push($temp_password, $letter);
      }
      // Get five numeric characters to complete the password
      for($row = 0; $row < 5; $row ++)
      {
        srand ((double) microtime() * 1000000);
        $rand_number = rand(0, 9);
        array_push($temp_password, $rand_number);
      }
      // Convert the array into a single string
      for ($row = 0; $row < count($temp_password); $row ++)
      {
        $password .=  $temp_password[$row];
      }
      // Return the password to the script that called the function
      return $password;
   }


By the way - I put this together one evening after consuming five pints of Jameson's 
with one arm tied behind my back and whilst wearing a blindfold!


Michael Egan



-----Original Message-----
From: Bryan Koschmann - GKT [mailto:[EMAIL PROTECTED]
Sent: 19 March 2003 07:44
To: PHP General
Subject: [PHP] random letter/character?[Scanned]


Hi,

I need to get a php script to print out a list of random characters. This
is the list:

a'
b'
c'
d'
e'
f'
g'
a''
b''
c''
d''
e''
f''
g''

They would be printed to a maximum of 50 in a row separated by spaces. Can
anyone give me a pointer as to how to do this? Since the rand functions
are only for numbers, maybe assign each character group a number?

Thanks in advance!

        Bryan


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


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

Reply via email to