This code generates a random floating point (decimal) number:
Usage:Code:<?
// Floating point random number function
function fprand($intMin,$intMax,$intDecimals) {
if($intDecimals) {
$intPowerTen=pow(10,$intDecimals);
return rand($intMin,$intMax*$intPowerTen)/$intPowerTen;
}
else
return rand($intMin,$intMax);
}
Code:// Example of fprand function
for($i=0; $i<=5; $i++) {
echo "Three random numbers with $i decimals are: ";
for($ii=1; $ii<=3; $ii++)
echo fprand(1,10,$i).' ';
echo '<br>';
}
?>
</span></span>
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks