Webmaster Forum
Design & Development => HTML & Website Design => Topic started by: Solushunz on August 11, 2011, 11:14:35 PM
-
I use this for generate random number by php code, but how to get the specific range
numbers.
<?php
echo rand() . "\n";
echo rand() . "\n";
?>
-
Creating a random number takes two commands called srand and rand. srand is a preparation command for rand. It helps rand create a truely random number. rand itself creates the random number. To make a random number within a specific range, you can add the number range in the rand command brackets.
-
try the following code.
rand(min,max), it will give you the number betweent min and max
-
To create random numbers in PHP, you can use the rand() function call, which takes either zero or, optionally, two parameters determining the minimum and maximum random numbers (inclusive) that you'd like. If you don't specify a maximum then it will default to a value, RAND_MAX, set in the PHP configuration. The function returns an integer, generated "randomly." (Computers can't generate real random numbers, but this tries and is suitable for most purposes.)