echo rand(); // Random Output 16513
echo rand(8,10); // Random Output starting from 8 to 10
Syntax
rand ( min,max);
min ,max : (Optional) Minimum and maximu value ( both inclusive ) of random integer to be generated ( both to be given ) <?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
$random_float = mt_rand() / mt_getrandmax();
echo $random_float;
mt_srand(123); // Seed the generator
echo mt_rand()."<br>"; // Output: Same number every time the script is run
echo mt_rand(); // Output: Same number every time the script is run
mt_srand(987);
echo mt_rand(); // Output will change with a different seed value
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.
princy | 02-02-2012 |
how to generate the random number in php |