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

Navigation:

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






 
 

SPONSORS



 
 

Random Number (practical example)

This example shows a practical example of producing random numbers . In this example we display a different die image based on the number which is produced . If we get a pair a message is displayed . In a future example we will produce a simple game using these methods.

here is the script

<?php
srand((double)microtime()*1000000);
//produce a random number between 1 and 6
$die1 = rand(1,6);
$die2 = rand(1,6);
//display die 1
echo "Die 1 is ";
echo "<img src=\"$die1.gif\">";
//display die 2
echo "Die 2 is ";
echo "<img src=\"$die2.gif\">";
//if die values are equal display message
If ($die1 == $die2)
echo "<br><b>you got a pair</b>";
?>

and here is the example


Die 1 is Die 2 is


You can download the images here