Page 1 of 1

how to genrate random string

Posted: Thu Jun 23, 2005 2:23 am
by itsmani1
hi there...
i want to genrate a random string like a3nd29sas3 can any one help me.
thanks.

Posted: Thu Jun 23, 2005 2:36 am
by method_man
ive searched this site and found some different solutions.

1.

Code: Select all

<?php
$string = password();//a function which returns 5 letters/numbers/mixed value
$check = mysql_num_rows(mysql_query("select password from table where password = '$string'"));
if($check > 0)
{
$rand = rand(10, 32);
$md = md5($string.time());
$string .= $md{$rand}.($check + 1);
}
?>
2.

Code: Select all

<?php
 
function makeRand ($minlength, $maxlength, $useupper, $usespecial, $usenumbers) 
  { //Random string generator
    $key="";
    $charset = "abcdefghijklmnopqrstuvwxyz";        
    if ($useupper)   $charset .= "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 
    if ($usenumbers) $charset .= "0123456789"; 
    if ($usespecial) $charset .= "~@#$%^*()_+-={}|][";   
    if ($minlength > $maxlength) $length = mt_rand ($maxlength, $minlength); 
    else                         $length = mt_rand ($minlength, $maxlength); 
    for ($i=0; $i<$length; $i++) $key .= $charset[(mt_rand(0,(strlen($charset)-1)))]; 
    return $key; 
  }
 
      do
      {
        $tempPass="";
        $tempPass=$this->utils->makeRand(15,15,1,0,1);        
      } while(in_array($tempPass,$arrPass));
 
//$arrPass is a array of present passwords
 
?>
and 3.

Code: Select all

require_once 'Text/Password.php'; //see http://pear.php.net/package/Text_Password
$password = Text_Password::create(8);
all 3 of these can be found on this url: viewtopic.php?t=22563&highlight=random+string

Posted: Thu Jun 23, 2005 2:36 am
by method_man
i think thats what your talking about

Posted: Thu Jun 23, 2005 2:49 am
by itsmani1
okies thanks let me try

Posted: Thu Jun 23, 2005 7:48 am
by Chris Corbyn
anjanesh wrote this little random text generator too...

(Conveniently named simpleRandomTextGenerater :P)

viewtopic.php?t=34337