rand, is used for randomizing numbers within it.
CODE
<?php
$random=rand(1,10);
echo $random;
?>
$random=rand(1,10);
echo $random;
?>
You will get a number between one and ten.
It is useful for creating fun guessing games.
It is also useful for attack scripts in online games, ive used it like this
CODE
rand($levelofuser1,$skillpointsofuser1) * 3
and
for the person being attacked:
CODE
rand($levelofuser2,$skillpointsofuser2)* 3
here is a small guessing game script:
CODE
//form.php
<?php
$rand=rand(1,10);
//that randomizes the number from 1 to 10..afcourse,,you can always change it to 1-100 or 20 -22..etc
if ($_POST['randnumber'] = $rand) {
echo "<font color='green'><b>Correctly Guessed!</b></font>";
}
else {
echo "Guess Again! The correct answer was ".$rand."";
}
?>
<form action='#' method='post'>
Guess a random number from one to ten :<br>
<input type='text' name='randnumber'><br>
<input type='submit' value='submit number' name='rbutton'>
</form>
<?php
$rand=rand(1,10);
//that randomizes the number from 1 to 10..afcourse,,you can always change it to 1-100 or 20 -22..etc
if ($_POST['randnumber'] = $rand) {
echo "<font color='green'><b>Correctly Guessed!</b></font>";
}
else {
echo "Guess Again! The correct answer was ".$rand."";
}
?>
<form action='#' method='post'>
Guess a random number from one to ten :<br>
<input type='text' name='randnumber'><br>
<input type='submit' value='submit number' name='rbutton'>
</form>
Have fun!

