note 74793 deleted from function.rand by felipe

From: Date: Sun, 30 Dec 2007 18:46:18 +0000
Subject: note 74793 deleted from function.rand by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-134456@lists.php.net to get a copy of this message
Note Submitter: DKDiveDude at Subima dot com ---- I was kind of surprised that PHP did not have a built-in floating point random number function. So I created my own: <? // Floating point random number function // April 2007, René W. Feuerlein function fprand($intMin,$intMax,$intDecimals) { if($intDecimals) { $intPowerTen=pow(10,$intDecimals); return rand($intMin,$intMax*$intPowerTen)/$intPowerTen; } else return rand($intMin,$intMax); } // 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>'; } ?>

« previous php.notes (#134456) next »