class ByteNumberGenerator implements NumberGenerator (View source)

A random number generator that wraps the given byte generator for generating integers.

Methods

__construct(Generator $generator)

NumberByteGenerator constructor.

bool
isSupported()

Tells if the underlying byte generator is supported by the system.

string
getBytes(int $count)

Returns bytes read from the provided byte generator.

int
getNumber(int $min, int $max)

Returns a random integer between given minimum and maximum.

Details

__construct(Generator $generator)

NumberByteGenerator constructor.

Parameters

Generator $generator The underlying byte generator used to generate random bytes

bool isSupported()

Tells if the underlying byte generator is supported by the system.

Return Value

bool True if the generator is supported, false if not

string getBytes(int $count)

Returns bytes read from the provided byte generator.

Parameters

int $count Number of bytes to return

Return Value

string Bytes generated by the secure random byte generator

Exceptions

GeneratorException If there was an error generating the bytes

int getNumber(int $min, int $max)

Returns a random integer between given minimum and maximum.

Parameters

int $min Minimum number to generate
int $max Maximum number to generate

Return Value

int Random number between the given limits

Exceptions

InvalidArgumentException If the provided values are invalid
GeneratorException If an error occurs generating the number