View Single Post

  #1 (permalink)  
Old 06-12-2004
Viruss
 
Posts: n/a
Default Random Floating point numbers

I am trying to write a function that will gerenerate a random number that is
of float value. Now I need it to generate between two values like so:

Lets say I have a value of .5 and 1.5. I want hte number to be between .5
and 1.5. Here is what I got so far:

function GetRandomValue($min, $max)
{
$range = $max-$min;
$num = $min + $range * mt_rand(0, 32767)/32767;

$num = round($num, 4);

return ((float) $num);
}

Now this seems to work to get me a value between like .04 and .03 but
nothing else. Anyone have any other suggestions?


Reply With Quote