Generate random floating-point values from 0 to 10 with two decimals : mt_rand « Math « PHP






Generate random floating-point values from 0 to 10 with two decimals

 
<?php 
function frand($min, $max, $decimals = 0) { 
    $scale = pow(10, $decimals); 
    return mt_rand($min * $scale, $max * $scale) / $scale; 
} 
echo "frand(0, 10, 2) = " . frand(0, 10, 2) . "\n"; 
?>
  
  








Related examples in the same category

1.int mt_rand ( [int min, int max] ) returns random numbers, similar to the rand( ).
2.Finding a random line of a file
3.Generate random numbers
4.Get a random value from 5 to 25.
5.Generate Password()
6.Get random values from –10 to 10.
7.Random floating-point values from 0 to 10 with two decimals
8.Random numbe with precision
9.Random values are not restricted to positive integers. The following example shows how to get random values from -10 to 10.