Main Menu

HOME

.Net
ASP
Assembly
C
C++
Delphi
HTML
Java
JavaScript
MySQL
PC interface
Powershell
Perl
PHP
VBScript
Visual Basic
XML

Make money selling software. Check this out here

Hosted clickbank mall. Check this out here




   Misc

   Amazon

   Links

    


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");
?>

 

 

 

 

 




   Sponsors
 

   Software
500 Java Tips E-book
PHP editor
PERL editor
Beginning Java
Beginning Visual Basic
Learn VB.net
Learn VB 6
VB and databases
ASP image library
C++ builder programming
C++ fundamentals

   Source Code
total no of colors(VB)
lowercase text(CSS)
basic addition example(Darkbasic)
Neon text(Javascript)
factorial function(VB)
Status bar clock(Javascript)
Replace a word(ASP)
Cool GD effect(PHP)

    




Copyright © 2003 by programmershelp.co.uk