Jump to content
xisto Community
Sign in to follow this  
ewcreators

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

Recommended Posts

We will now discuss rand().
rand, is used for randomizing numbers within it.

<?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
rand($levelofuser1,$skillpointsofuser1) * 3
and
for the person being attacked:
rand($levelofuser2,$skillpointsofuser2)* 3


here is a small guessing game script:
//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..etcif ($_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!

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.