This is a discussion on Random Floating point numbers within the alt.comp.lang.php forums, part of the PHP Programming Forums category; I am trying to write a function that will gerenerate a random number that is of float value. Now I ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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? |
|
|||
|
"Viruss" <haha@hah.ca> wrote in message
news:RiAyc.734446$oR5.666689@pd7tw3no... > 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? > > Never mind that function seems to have taken care of it I was entering bad data. Thanks though |