interface NumberGenerator implements Generator (View source)

Interface for generators that can also generate random numbers.

Methods

bool
isSupported()

Tells if the generator is supported by the operating system.

from Generator
string
getBytes(int $count)

Returns securely generated random bytes.

from Generator
int
getNumber(int $min, int $max)

Returns a securely generated random number between minimum and maximum.

Details

bool isSupported()

Tells if the generator is supported by the operating system.

Return Value

bool True if the generator is supported, false if not

string getBytes(int $count)

Returns securely generated random bytes.

This method will always return the correct number of bytes that have been securely generated. If the bytes cannot be securely generated or if the correct number of bytes cannot be generated, the method MUST throw an exception.

Parameters

int $count Number of bytes to return

Return Value

string Bytes generated by the secure random byte generator

Exceptions

GeneratorException If any error occurs

int getNumber(int $min, int $max)

Returns a securely generated random number between 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

GeneratorException If any errors occurs in the random number generation