$systemPrecision
$systemPrecision : integer|null
The default system precision storage.
Class AbstractGenerator - Abstraction for pseudo-random generator classes.
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.
null|integer | $precision | Rounding precision (default => 10). |
Validation errors.
Randomly generated probability value.
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.
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). |
Validation errors.
Randomly generated float value.
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.
null|integer | $precision | Rounding precision (default => 2). |
boolean|integer | $lowerTheScope | Flag for using a smaller calculation range. |
Validation errors.
Randomly generated percentage value.
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
.
boolean|integer | $asInteger | Flag for returning as integer (default => true). |
Validation errors.
Randomly generated ternary value.
getHex(integer $length = 1, boolean $upperCase = false) : string
Generate a random HEX string.
integer | $length | The output string length (default => 1). |
boolean | $upperCase | Flag for using uppercase output (default => false). |
Validation errors.
Randomly generated HEX string.
getBase64(integer $length = 1, boolean $urlFriendly = false) : string
Generate a random Base64 string.
integer | $length | The internal byte string length (default => 1). |
boolean | $urlFriendly | Flag for using URL friendly output (default => false). |
Validation errors.
Randomly generated Base64 RFC 4648 standard string.
getLetter(boolean $caseSensitive = true) : string
Generate a random english letter character.
boolean | $caseSensitive | Flag for enabling case sensitive generation (default => true). |
Validation errors.
Randomly generated english letter character.
getAlphaNumeric(integer $length = 1, boolean $caseSensitive = true) : string
Generate a random alphanumeric string.
integer | $length | The output string length (default => 1). |
boolean | $caseSensitive | Flag for enabling case sensitive generation (default => true). |
Validation errors.
Randomly generated alphanumeric string.
getAscii(integer $length = 1, boolean|integer $includeSpace = false) : string
Generate a random ASCII (American Standard Code) string containing only printable characters.
integer | $length | The output string length (default => 1). |
boolean|integer | $includeSpace | Flag for including the space character (default => true). |
Validation errors.
Randomly generated ASCII string.
getString(integer $length = 1, array $characters = array()) : string
Generate a random string with custom characters.
integer | $length | The output string length (default => 1). |
array | $characters | The character map for the string generation (default => ASCII). |
Validation errors.
Randomly generated string using a custom character map.
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).
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). |
Validation errors.
Randomly generated GUID string representing a 128-bit number.
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.
string | $prefix | Optional prefix for output strings (default => ''). |
boolean | $alphaNumeric | Flag for switching to alphanumerical format (default => false). |
Validation errors.
Randomly generated strong hexadecimal/alphanumerical UUID string.
getRgbColourPair(boolean $toArray = true) : array|string
Generate a random Red-Green-Blue (RGB) colour combination using all colours.
boolean | $toArray | Flag to force array output instead of string (default => true). |
Validation errors.
Randomly generated RGB array or hexadecimal RGB color.
getRgbGreyscalePair(boolean $toArray = true) : array|string
Generate a random Red-Green-Blue (RGB) colour combination using only greyscale colours.
boolean | $toArray | Flag to force array output instead of string (default => true). |
Validation errors.
Randomly generated RGB array or hexadecimal RGB color.
getRgbBlackOrWhitePair(boolean $toArray = true) : array|string
Generate a random Red-Green-Blue (RGB) colour combination using only black&white colours.
boolean | $toArray | Flag to force array output instead of string (default => true). |
Validation errors.
Randomly generated RGB array or hexadecimal RGB color.
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.
null|integer | $from | The lowest value to be returned (default => 0). |
null|integer | $to | The highest value to be returned (default => $this->getMaxNumber()). |
Randomly generated integer number.
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.
null|integer | $precision | The wanted precision for the machine epsilon. |
The machine epsilon used for floating number comparison operations.
validateNumericOrDefault(integer|float|null $from, integer|float|null $to)
Internal method for double range supported types validation.
integer|float|null | $from | The minimum number in the wanted range. |
integer|float|null | $to | The maximum number in the wanted range. |
Validation errors.
validateDoubleRange(integer|float $from, integer|float $to, null|integer $precision = 14)
Internal method for double range validation.
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. |
Validation errors.
improvePoorFloatOutput(float $from, float $to, integer $precision)
Improve the quality of the algorithm used for floating numbers generation.
float | $from | The lowest value to be returned. |
float | $to | The highest value to be returned. |
integer | $precision | Rounding precision for epsilon calculation. |
calculateRgbArrayToHexString(array $rgbColour) : string
Internal method for converting RGB integer colours to HEX notations.
array | $rgbColour | An array containing three integers between 0 and 255. |
The HEX representation of the RGB colour pair.
validatePositiveInteger(integer $integer, boolean $includeZero = false)
Internal method for validation of positive integers.
integer | $integer | The positive integer value. |
boolean | $includeZero | Flag for enabling the zero as a valid value. |
Validation errors.