(PHP 8 >= 8.3.0)
Random\Randomizer::getFloat — Get a uniformly selected float
$min, float $max, Random\IntervalBoundary $boundary = Random\IntervalBoundary::ClosedOpen): float
This function is currently not documented; only its argument list is available.
minThe lower bound of the interval.
maxThe upper bound of the interval.
boundarySpecifies if the interval boundaries are possible return values.
A uniformly selected float from the interval specified by min, max,
and boundary. Whether min and max
are possible return values depends on the value of boundary.
$min is not finite,
a ValueError will be thrown.
$max is not finite,
a ValueError will be thrown.
Random\Randomizer::$engine.
Example #1 Random\Randomizer::getFloat() example
<?php
$randomizer = new \Random\Randomizer();
// Note that the latitude granularity is double the
// longitude’s granularity.
//
// For the latitude the value may be both -90 and 90.
// For the longitude the value may be 180, but not -180, because
// -180 and 180 refer to the same longitude.
printf(
"Lat: %+.6f Lng: %+.6f",
$randomizer->getFloat(-90, 90, \Random\IntervalBoundary::ClosedClosed),
$randomizer->getFloat(-180, 180, \Random\IntervalBoundary::OpenClosed),
);
?>The above example will output something similar to:
Lat: 69.244304 Lng: -53.548951
Note:
This method implements the γ-section algorithm as published in » Drawing Random Floating-Point Numbers from an Interval. Frédéric Goualard, ACM Trans. Model. Comput. Simul., 32:3, 2022 to obtain the desired behavioral properties.