View Full Version : making random string

02-19-2004, 05:36 PM
to all,
is there an in built function in php that cna generate a random string? example:

rand() are for generating numbers right?

so what is the function for generating a string?what i mean of string is like probably---> fsr45mdk43 or something like that.

pls help..thanking u in advance.

02-19-2004, 05:48 PM
I used to have quite a nice way of making a random string but I have forgotten it. I think it used rand though.

This is how invisionboard generate a random password

function make_password()
$pass = "";
$chars = array(

$count = count($chars) - 1;


for($i = 0; $i < 8; $i++)
$pass .= $chars[rand(0, $count)];


you could obviously change the length and function name. Also, i think the (double) method is no longer used so, you could replace:



$microtime = microtime()*1000000;
settype($microtime, 'float');

02-19-2004, 06:14 PM
this link may help you. ( http://www.phpnoise.com/tutorials/1/2 )
on this site is uses $string = md5(rand(0,9999));
I have tried it out and it works. you just have to use substr($string,start#,end#); to get the desired string length.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum