Properties

$systemPrecision

$systemPrecision : integer|null

The default system precision storage.

Type

integer|null — The used default floating number precision.

$seed

$seed : boolean|integer

The initialization seed value property storage for all instances.

Type

boolean|integer — The generator's seed value.

Methods

__construct()

__construct() 

Randomness source constructor.

__wakeup()

__wakeup() 

Randomness generator reinitialization tasks after unserialization.

getProbability()

getProbability(null|integer  $precision = 10) : float

Generate a probability format float number between 0.0 and 1.0.

Note: Passing null will use the global system precision value.

Parameters

null|integer $precision

Rounding precision (default => 10).

Throws

\Exception

Validation errors.

Returns

float —

Randomly generated probability value.

getFloat()

getFloat(null|float|integer  $from = 0.0, null|float|integer  $to = null, null|integer  $precision = 8) : float

Generate a random float number in a certain range.

Note: Passing null will use the default parameter value or for precision the global system value.

Parameters

null|float|integer $from

The lowest value to be returned (default => 0.0).

null|float|integer $to

The highest value to be returned (default => (float)$this->getMaxNumber()).

null|integer $precision

Rounding precision (default => 8).

Throws

\Exception

Validation errors.

Returns

float —

Randomly generated float value.

getPercent()

getPercent(null|integer  $precision = 2, boolean|integer  $lowerTheScope = false) : float

Generate a percentage format float number between 0.0 and 100.0.

Note: Passing null will use the global system precision value.

Parameters

null|integer $precision

Rounding precision (default => 2).

boolean|integer $lowerTheScope

Flag for using a smaller calculation range.

Throws

\Exception

Validation errors.

Returns

float —

Randomly generated percentage value.

getBool()

getBool() : boolean

Generate a random boolean.

Throws

\Exception

Validation errors.

Returns

boolean —

Randomly generated boolean value.

getTernary()

getTernary(boolean|integer  $asInteger = true) : boolean|integer

Generate a random ternary format (-1, 0, 1).

Note: Passing false to the $asInteger parameter will convert values to null, false and true.

Parameters

boolean|integer $asInteger

Flag for returning as integer (default => true).

Throws

\Exception

Validation errors.

Returns

boolean|integer —

Randomly generated ternary value.

getHex()

getHex(integer  $length = 1, boolean  $upperCase = false) : string

Generate a random HEX string.

Parameters

integer $length

The output string length (default => 1).

boolean $upperCase

Flag for using uppercase output (default => false).

Throws

\Exception

Validation errors.

Returns

string —

Randomly generated HEX string.

getBase64()

getBase64(integer  $length = 1, boolean  $urlFriendly = false) : string

Generate a random Base64 string.

Parameters

integer $length

The internal byte string length (default => 1).

boolean $urlFriendly

Flag for using URL friendly output (default => false).

Throws

\Exception

Validation errors.

Returns

string —

Randomly generated Base64 RFC 4648 standard string.

getDigit()

getDigit(boolean  $includeZero = true) : string

Generate a random digit character.

Parameters

boolean $includeZero

Flag for including the zero digit (default => true).

Throws

\Exception

Validation errors.

Returns

string —

Randomly generated digit character.

getLetter()

getLetter(boolean  $caseSensitive = true) : string

Generate a random english letter character.

Parameters

boolean $caseSensitive

Flag for enabling case sensitive generation (default => true).

Throws

\Exception

Validation errors.

Returns

string —

Randomly generated english letter character.

getAlphaNumeric()

getAlphaNumeric(integer  $length = 1, boolean  $caseSensitive = true) : string

Generate a random alphanumeric string.

Parameters

integer $length

The output string length (default => 1).

boolean $caseSensitive

Flag for enabling case sensitive generation (default => true).

Throws

\Exception

Validation errors.

Returns

string —

Randomly generated alphanumeric string.

getAscii()

getAscii(integer  $length = 1, boolean|integer  $includeSpace = false) : string

Generate a random ASCII (American Standard Code) string containing only printable characters.

Parameters

integer $length

The output string length (default => 1).

boolean|integer $includeSpace

Flag for including the space character (default => true).

Throws

\Exception

Validation errors.

Returns

string —

Randomly generated ASCII string.

getString()

getString(integer  $length = 1, array  $characters = array()) : string

Generate a random string with custom characters.

Parameters

integer $length

The output string length (default => 1).

array $characters

The character map for the string generation (default => ASCII).

Throws

\Exception

Validation errors.

Returns

string —

Randomly generated string using a custom character map.

getGloballyUniqueId()

getGloballyUniqueId(string  $prefix = '', boolean  $withDashes = true, boolean  $upperCase = false) : string

Generate a random version 4 Globally Unique Identifier (GUID) standard string.

Note: The identifier string uses 32 alphanumeric characters and 4 hyphens (optional).

Parameters

string $prefix

Optional prefix for output strings (default => '').

boolean $withDashes

Flag for using dashes format (default => true).

boolean $upperCase

Flag for using uppercase format (default => false).

Throws

\Exception

Validation errors.

Returns

string —

Randomly generated GUID string representing a 128-bit number.

getStrongUniqueId()

getStrongUniqueId(string  $prefix = '', boolean  $alphaNumeric = false) : string

Generate a strong Universally Unique Identifier (UUID) string in hexadecimal or alphanumeric format.

Note: The identifier string is exactly 128 characters long.

Parameters

string $prefix

Optional prefix for output strings (default => '').

boolean $alphaNumeric

Flag for switching to alphanumerical format (default => false).

Throws

\Exception

Validation errors.

Returns

string —

Randomly generated strong hexadecimal/alphanumerical UUID string.

getRgbColourPair()

getRgbColourPair(boolean  $toArray = true) : array|string

Generate a random Red-Green-Blue (RGB) colour combination using all colours.

Parameters

boolean $toArray

Flag to force array output instead of string (default => true).

Throws

\Exception

Validation errors.

Returns

array|string —

Randomly generated RGB array or hexadecimal RGB color.

getRgbGreyscalePair()

getRgbGreyscalePair(boolean  $toArray = true) : array|string

Generate a random Red-Green-Blue (RGB) colour combination using only greyscale colours.

Parameters

boolean $toArray

Flag to force array output instead of string (default => true).

Throws

\Exception

Validation errors.

Returns

array|string —

Randomly generated RGB array or hexadecimal RGB color.

getRgbBlackOrWhitePair()

getRgbBlackOrWhitePair(boolean  $toArray = true) : array|string

Generate a random Red-Green-Blue (RGB) colour combination using only black&white colours.

Parameters

boolean $toArray

Flag to force array output instead of string (default => true).

Throws

\Exception

Validation errors.

Returns

array|string —

Randomly generated RGB array or hexadecimal RGB color.

getMaxNumber()

getMaxNumber() : integer

The maximum supported integer.

Returns

integer —

The upper integer generation border.

getMinNumber()

getMinNumber() : integer

The minimum supported integer.

Returns

integer —

The lower integer generation border.

getInt()

getInt(null|integer  $from, null|integer  $to = null) : integer

Generate a random integer number in a certain range.

Note: Passing null will use the default parameter value.

Parameters

null|integer $from

The lowest value to be returned (default => 0).

null|integer $to

The highest value to be returned (default => $this->getMaxNumber()).

Throws

\Exception

Validation errors.

Returns

integer —

Randomly generated integer number.

getBytes()

getBytes(integer  $length = 1) : string

Generate a random byte string.

Note: PHP represents bytes as characters to make byte strings.

Parameters

integer $length

The output string length (default => 1).

Throws

\Exception

Validation errors.

Returns

string —

Randomly generated string containing the requested number of bytes.

__debugInfo()

__debugInfo() : array

Get debug information for the class instance.

Returns

array —

Debug information.

validateIntegerRange()

validateIntegerRange(integer  $from, integer  $to) 

Internal method for integer range validation.

Parameters

integer $from

The minimum number in the wanted range.

integer $to

The maximum number in the wanted range.

Throws

\Exception

Validation errors.

validatePositiveInteger()

validatePositiveInteger(integer  $integer, boolean  $includeZero = false) 

Internal method for validation of positive integers.

Parameters

integer $integer

The positive integer value.

boolean $includeZero

Flag for enabling the zero as a valid value.

Throws

\Exception

Validation errors.

calculateEpsilon()

calculateEpsilon(null|integer  $precision = null) : float

Internal method for calculating the machine epsilon value based on the used precision.

Note: Passing null will use the global system precision value.

Parameters

null|integer $precision

The wanted precision for the machine epsilon.

Returns

float —

The machine epsilon used for floating number comparison operations.

calculateLowQualityPercent()

calculateLowQualityPercent(integer  $max) : float

Generate a low quality percentage format float number between 0.0 and 100.0.

Parameters

integer $max

The upper scope number used for internal generation.

Returns

float —

Randomly generated low quality percentage value.

validateNumericOrDefault()

validateNumericOrDefault(integer|float|null  $from, integer|float|null  $to) 

Internal method for double range supported types validation.

Parameters

integer|float|null $from

The minimum number in the wanted range.

integer|float|null $to

The maximum number in the wanted range.

Throws

\Exception

Validation errors.

validateDoubleRange()

validateDoubleRange(integer|float  $from, integer|float  $to, null|integer  $precision = 14) 

Internal method for double range validation.

Parameters

integer|float $from

The minimum number in the wanted range.

integer|float $to

The maximum number in the wanted range.

null|integer $precision

The used precision for comparison.

Throws

\Exception

Validation errors.

validateCharacterMap()

validateCharacterMap(array  $charMap) 

Internal method for character map validation.

Parameters

array $charMap

The character map array.

Throws

\Exception

Validation errors.

calculateRgbArrayToHexString()

calculateRgbArrayToHexString(array  $rgbColour) : string

Internal method for converting RGB integer colours to HEX notations.

Parameters

array $rgbColour

An array containing three integers between 0 and 255.

Returns

string —

The HEX representation of the RGB colour pair.

getInteger()

getInteger(integer  $minimum, integer  $maximum) : integer

Internal static method for single point consumption of the randomness source that outputs integers.

Parameters

integer $minimum

The lowest value to be returned.

integer $maximum

The highest value to be returned.

Throws

\Exception

If no suitable random source is found.

Returns

integer —

Randomly generated integer number.

getEightBits()

getEightBits(integer  $count) : string

Internal static method for single point consumption of the randomness source that outputs bytes.

Parameters

integer $count

The output string length based on the requested number of bytes.

Throws

\Exception

If no suitable random source is found.

Returns

string —

Randomly generated string containing the requested number of bytes.