Alexey Berezuev Alexey Berezuev - 7 days ago 6
PHP Question

PHP How do I rand float value?

$a = floatval(0.0001);
$b = floatval(0.0009);
$c = rand($a,$b); // int(0);


How can I get rand from
$a
to
$b
floats?

Multiplication of
$
a and
$b
is not solution, because I don't know number of digits after dot.

Answer

From this article:

An elegant way to return random float between two numbers:

function random_float ($min,$max) {
   return ($min+lcg_value()*(abs($max-$min)));
}