SQL PHP HTML ASP JavaScript articles and free scripts to download

Random number generator

We can generate random value by using PHP. We can specify a range and the random value between those two ranges (inclusive) will be generated.


Note that here we are generating a random number only. To get any random characters we can use arrays. The details on how to generate random characters is available here.


Here is the code to generate random numbers.

echo "<br>Random Value = ".rand(5,10);    
// Will display random value between 5 and 10 ( both inclusive )

Random number of different length

We can create a script to generate random number of different length. Let us try to develop a script to print random number of 5 character length.

Here it is

<?Php
$no_of_digits=5;
$var='';
for($i=1; $i<=$no_of_digits; $i++){
$var .=rand(0,9);
}
echo "<br>Random Value = $var";
?>

Output is here

Random Value = 33369

Read here how to generate random string having alphabets and digits

Number of User Comments : 1


Google+

princy02-02-2012
how to generate the random number in php
Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy



HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2015 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer