Generate a random letter in PHP

The easy-to-understand way:

function randomLetter()
{
    $int = rand(0,51);
    $a_z = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    $rand_letter = $a_z[$int];
    return $rand_letter;
}

The geeky, very efficient way:

function randomLetter(){
  return chr(97 + mt_rand(0, 25));
}

Oct24

Leave a Reply




*