Alexey Berezuev Alexey Berezuev - 10 months ago 167
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

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

Answer Source

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)));