Random letters
The principles for generating random letters are similar to random numbers . In this example we will generate a random lower case number and then a random upper case number.
As you are aware to generate a random number you can do something like this
rand(1,6);
This wont work for letters so youy cant do something like rand(a,z); . Instead we need to get the ascii value of our letter in the range .
To get the ascii value of a letter for example the letter "a" we do this
echo ord("a");
Which gives us the following
97
So to get the range from a to z we can try this
$random_letter_lcase = chr(rand(ord("a"), ord("z")));
Here is our complete script
<?php
srand(time());
$random_letter_lcase = chr(rand(ord("a"), ord("z")));
$random_letter_ucase = chr(rand(ord("A"), ord("Z")));
echo ("your letter is $random_letter_lcase");
echo ("<br>");
echo ("your letter is $random_letter_ucase");
?>
And here is the result
your letter is o
your letter is A