Page 1 of 1

Random number to 4 DP

Posted: Sun Aug 31, 2003 7:44 am
by megaming
Does anyone know how to get a random number with a lower bound of 0.0001 and an upper bound of 100.0000 ?

This would help me greatly, thank you :D

Posted: Sun Aug 31, 2003 7:54 am
by JAM
Dunno if this results in what you desire, but a good start perhaps:

Code: Select all

<pre>
<?php 
$upperBound = 100.0000;
$lowerBound = 0.0001;
$range = $upperBound-$lowerBound; 
$num = $lowerBound + $range * mt_rand(0, 32767)/32767;
echo round($num,4);
?>

Posted: Sun Aug 31, 2003 7:58 am
by megaming
Hmm... looks like it could work. I don't need the code for a couple of days, I'm just asking so I don't have to wait when I do need it :)

If anyone else has alternative methods, then that could still help incase this one doesn't work.

Thank you :D

Posted: Sun Aug 31, 2003 8:10 am
by JAM
megaming wrote:I'm just asking so I don't have to wait when I do need it :)
Hehe, good call.