note 74824 added to function.rand

From: Date: Sun, 29 Apr 2007 15:24:14 +0000
Subject: note 74824 added to function.rand
Groups: php.notes 
Request: Send a blank email to php-notes+get-125960@lists.php.net to get a copy of this message
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); } ?> ---- Server IP: 83.137.20.120 Probable Submitter: 86.82.192.241 ---- Manual Page -- http://www.php.net/manual/en/function.rand.php Edit -- https://master.php.net/note/edit/74824 Del: integrated -- https://master.php.net/note/delete/74824/integrated Del: useless -- https://master.php.net/note/delete/74824/useless Del: bad code -- https://master.php.net/note/delete/74824/bad+code Del: spam -- https://master.php.net/note/delete/74824/spam Del: non-english -- https://master.php.net/note/delete/74824/non-english Del: in docs -- https://master.php.net/note/delete/74824/in+docs Del: other reasons-- https://master.php.net/note/delete/74824 Reject -- https://master.php.net/note/reject/74824 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#125960) next »