Home | Scripts | Tutorials | Books | Hosting | Forums | Links|

Navigation:

Home
Source code
Tutorials
RSS feeds
Articles
Books
Software
Downloads
Hosting
manuals
Forums
Script directory
Training
Our Links

ADD TO Progged Progged
ADD TO DEL.ICIO.US Del.icio.
ADD TO DIGG Digg
ADD TO FURL Furl
ADD TO NEWSVINE Newsvine
ADD TO NETSCAPE Netscape
ADD TO REDDIT Reddit
ADD TO STUMBLEUPON StumbleUpon
ADD TO TECHNORATI FAVORITES Technorati
ADD TO SQUIDOO Squidoo
ADD TO WINDOWS LIVE Windows Live
ADD TO YAHOO MYWEB Yahoo MyWeb
ADD TO ASK Ask
ADD TO GOOGLE Google
ADD TO MAGNOLIA Magnolia
ADD TO SPURL Spurl



 
 

SPONSORS



 
 

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