Randomizer
final class Randomizer (View source)
Provides a high-level API to the randomness provided by an Random\Engine.
Properties
| Engine | $engine |
Methods
Get a positive integer
Get a uniformly selected integer
Get random bytes
Get a permutation of an array
Get a byte-wise permutation of a string
Select random array keys
Serializes the Randomizer object
Deserializes the data parameter into a Randomizer object
Get a float from the right-open interval [0.0, 1.0)
Get a uniformly selected float
Get random bytes from a source string
Details
__construct(Engine|null $engine = null)
Constructs a new Randomizer
int
nextInt()
Get a positive integer
int
getInt(int $min, int $max)
Get a uniformly selected integer
string
getBytes(int $length)
Get random bytes
Generates a string containing uniformly selected random bytes with the requested length.
array
shuffleArray(array $array)
Get a permutation of an array
Returns a uniformly selected permutation of the input array.
string
shuffleBytes(string $bytes)
Get a byte-wise permutation of a string
Returns a uniformly selected permutation of the input bytes.
array
pickArrayKeys(array $array, int $num)
Select random array keys
Uniformly selects num distinct array keys of the input array.
array
__serialize()
Serializes the Randomizer object
void
__unserialize(array $data)
Deserializes the data parameter into a Randomizer object
float
nextFloat()
Get a float from the right-open interval [0.0, 1.0)
Returns a uniformly selected, equidistributed float from the right-open interval from 0.0 until, but not including, 1.0.
float
getFloat(float $min, float $max, IntervalBoundary $boundary = IntervalBoundary::ClosedOpen)
Get a uniformly selected float
Returns a uniformly selected, equidistributed float from a requested interval.
string
getBytesFromString(string $string, int $length)
Get random bytes from a source string
Generates a string containing uniformly selected random bytes from the input string with the requested length.