note 74824 deleted from function.rand by felipe

From: Date: Sun, 30 Dec 2007 18:46:25 +0000
Subject: note 74824 deleted from function.rand by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-134457@lists.php.net to get a copy of this message
Note Submitter: blackened at live dot com ---- DKDiveDude forgot one thing in his function. I tested it, and I found out the random output could even be smaller then $intMin. This was because he forgot to multiply $intMin with $intPowerTen. Below DKDiveDude's function with the edit <?php // Floating point random number function // April 2007, René W. Feuerlein function fprand($intMin,$intMax,$intDecimals) { if($intDecimals) { $intPowerTen=pow(10,$intDecimals); return rand($intMin*$intPowerTen,$intMax*$intPowerTen)/$intPowerTen; } else return rand($intMin,$intMax); } ?>

« previous php.notes (#134457) next »