Jul 26, 2008

Rand() - Another the artists tut, this time small.

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > PHP Programming

free web hosting

Rand() - Another the artists tut, this time small.

ewcreators
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!

 

 

 


Reply

galexcd
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.

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : rand artists tut

  1. The Artists Tutorials :mysql Basic Commands - The Artists is an online programming unit and gfx designing clan. (0)



Looking for rand, artists, tut, time, small,

Searching Video's for rand, artists, tut, time, small,
advertisement



Rand() - Another the artists tut, this time small.



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE