Mega Code Archive

 
Categories / Php / Algorithms
 

Creates a random string of x characters, using a defined string of possible characters

<? function randomString($len) { srand(date("s")); $possible="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890!@#$%^&*()"; $str=""; while(strlen($str)<$len) { $str.=substr($possible,(rand()%(strlen($possible))),1); } return($str); } ?>