Sometimes it becomes necessary to generate some random string code for verifying account email or to generate default password for user accounts. So today I’ll provide you code for a user defined function that’ll  help you to generate random string .

function rand_string( $length )  
{
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$size = strlen( $chars ); 
for( $i = 0; $i < $length; $i++ ) 
{
$str .= $chars[ rand( 0, $size - 1 ) ];
}
return $str; 
}