Page 1 of 1
rand()
Posted: Thu Mar 03, 2005 4:46 pm
by cbrian
Code: Select all
<?php
$min = 0.090000 * $lrand;
$max = 0.100000 * $lrand;
$gain = rand($min, $max);
?>
$lrand is stated above in the code, it is not the problem.
Most of the time this equals 0, but when i raise $lrand it goes to 1 sometimes. How can I used rand() to use decimals and not round to nearest whole number?
Posted: Thu Mar 03, 2005 4:52 pm
by feyd
int rand ( [int min, int max] )
notice that it says int, as in integer.
Scale the values past the decimal level you wish to rand against.. alternately.. you can use the rand as a scalar value. such as
Code: Select all
$scalar = rand(0,10000) / 10000;
$min = 0.9;
$max = 0.1;
$level = ($max - $min) * $scalar + $min;
Posted: Thu Mar 03, 2005 5:23 pm
by cbrian
Okay, thanks.