note 74793 added to function.rand
| From: | DKDiveDude at Subima dot com | Date: | Fri, 27 Apr 2007 15:44:39 +0000 |
| Subject: | note 74793 added to function.rand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-125922@lists.php.net to get a copy of this message | ||
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>';
}
?>
----
Server IP: 69.39.81.135
Probable Submitter: 70.11.185.195
----
Manual Page -- http://www.php.net/manual/en/function.rand.php
Edit -- https://master.php.net/note/edit/74793
Del: integrated -- https://master.php.net/note/delete/74793/integrated
Del: useless -- https://master.php.net/note/delete/74793/useless
Del: bad code -- https://master.php.net/note/delete/74793/bad+code
Del: spam -- https://master.php.net/note/delete/74793/spam
Del: non-english -- https://master.php.net/note/delete/74793/non-english
Del: in docs -- https://master.php.net/note/delete/74793/in+docs
Del: other reasons-- https://master.php.net/note/delete/74793
Reject -- https://master.php.net/note/reject/74793
Search -- https://master.php.net/manage/user-notes.php