This PHP function creates a random string that can be used as a password generation tool for your website.You can generate an alphabetic,numeric,alphanumeric or alphanumeric with symbols random string that can be used as a random password.Just modify the array in the code to which characters you will use in the string.The string length can be specified in the parameter.If no parameter has been st,default will be 8.Just call the function and specify the length in the parameter(optional) then you have a random string generated.
function random_generator($digits){
if ($digits==”")
{
$digits=8; //specify default length if empty
}
srand ((double) microtime() * 10000000);
//Array of alphabets
$input = 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”,”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”);$random_generator=”";// Initialize the string to store random numbers
for($i=1;$i<$digits+1;$i++){ // Loop the number of times of required digitsif(rand(1,2) == 1){// to decide the digit should be numeric or alphabet
// Add one random alphabet
$rand_index = array_rand($input);
$random_generator .=$input[$rand_index]; // One char is added}else{
// Add one numeric digit between 1 and 10
$random_generator .=rand(1,10); // one number is added
} // end of if else} // end of for loop
return $random_generator;
}echo random_generator(10); //call the function












