Random\Randomizer::getFloat

(PHP 8 >= 8.3.0)

Random\Randomizer::getFloatGet a uniformly selected float

Description

public Random\Randomizer::getFloat(float $min, float $max, Random\IntervalBoundary $boundary = Random\IntervalBoundary::ClosedOpen): float

Warning

This function is currently not documented; only its argument list is available.

Parameters

min

The lower bound of the interval.

max

The upper bound of the interval.

boundary

Specifies if the interval boundaries are possible return values.

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.

Errors/Exceptions

Examples

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

Notes

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.

See Also