diff --git a/reference/random/random/randomizer/nextfloat.xml b/reference/random/random/randomizer/nextfloat.xml index 02a04d3924b2..881c9e29ccf6 100644 --- a/reference/random/random/randomizer/nextfloat.xml +++ b/reference/random/random/randomizer/nextfloat.xml @@ -15,8 +15,21 @@ - &warn.undocumented.func; - + + + Scaling the return value to a different interval using multiplication + or addition (a so-called affine transformation) might result in a bias + in the resulting value as floats are not equally dense across the number + line. As not all values can be exactly represented by a float, the + result of the affine transformation might also result in values outside + of the requested interval. + + + Use Random\Randomizer::getFloat to generate a + random float within an arbitrary interval. Use Random\Randomizer::getInt + to generate a random integer within an arbitrary interval. + + @@ -41,7 +54,7 @@ &reftitle.examples; - + <methodname>Random\Randomizer::nextFloat</methodname> example + + + + + Incorrect scaling using an affine transformation + +nextFloat() * ($max - $min) + $min); + +// Correct: +// $randomizer->getFloat($min, $max, \Random\IntervalBoundary::ClosedOpen); +?> +]]> + + &example.outputs; + +