Mega Code Archive

 
Categories / Php / Math
 

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";  ?>