Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Rand(), Another the artists tut, this time small.
ewcreators
post Aug 29 2007, 07:32 AM
Post #1


Member [Level 1]
****

Group: Members
Posts: 59
Joined: 28-August 07
Member No.: 48,983



We will now discuss rand().
rand, is used for randomizing numbers within it.
CODE
<?php
$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>


Have fun!
Go to the top of the page
 
+Quote Post
galexcd
post Sep 6 2007, 07:28 PM
Post #2


Define:EVIL PROGRAMMER (ē'vəl prō'grăm'ər)- n. An organism that converts caffeine into evil software.
*********

Group: [HOSTED]
Posts: 993
Joined: 25-September 05
From: L.A.
Member No.: 12,251



I love the rand function in php, in most other languages like java, and js, rand dosn't take paramaters and it gives you a random float between 0 and 1, then you have to multiply and add to it and then top it off with a round to get the same result as the nice php random int function.
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. The Artists Tutorials :mysql Basic Commands(0)


 



- Lo-Fi Version Time is now: 8th August 2008 - 12:13 AM