Webmaster Forum

Design & Development => HTML & Website Design => Topic started by: Solushunz on August 11, 2011, 11:14:35 PM

Title: random number in php
Post 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.

Code: [Select]
<?php
echo rand() . "\n";
echo 
rand() . "\n";
?>
Title: Re: random number in php
Post by: ajans on August 16, 2011, 10:16:26 PM
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.
Title: Re: random number in php
Post by: whowho on September 17, 2011, 01:44:24 AM
try the following code.

rand(min,max), it will give you the number betweent min and max
Title: Re: random number in php
Post by: jbard on December 17, 2011, 08:22:36 PM
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.)