Pseudorandom number generator (PRNG)

package Default

 Methods

Retrieve a fallback/alternative RNG generator

getAlternativeGenerator() : \RandomLib\Generator
Static

Returns

\RandomLib\Generator

Generate random boolean

getBoolean(boolean $strong = false) : boolean
Static

Parameters

$strong

boolean

true if you need a strong random generator (cryptography)

Returns

boolean

Generate random bytes using OpenSSL or Mcrypt and mt_rand() as fallback

getBytes(integer $length, boolean $strong = false) : string
Static

Parameters

$length

integer

$strong

boolean

true if you need a strong random generator (cryptography)

Exceptions

\Zend\Math\Exception\RuntimeException

Returns

string

Generate random float (0.

getFloat(boolean $strong = false) : float
Static

.1) This function generates floats with platform-dependent precision

PHP uses double precision floating-point format (64-bit) which has 52-bits of significand precision. We gather 7 bytes of random data, and we fix the exponent to the bias (1023). In this way we generate a float of 1.mantissa.

Parameters

$strong

boolean

true if you need a strong random generator (cryptography)

Returns

float

Generate a random integer between $min and $max

getInteger(integer $min, integer $max, boolean $strong = false) : integer
Static

Parameters

$min

integer

$max

integer

$strong

boolean

true if you need a strong random generator (cryptography)

Exceptions

\Zend\Math\Exception\DomainException

Returns

integer

Generate a random string of specified length.

getString(integer $length, string|null $charlist = null, boolean $strong = false) : string
Static

Uses supplied character list for generating the new string. If no character list provided - uses Base 64 character set.

Parameters

$length

integer

$charlist

stringnull

$strong

boolean

true if you need a strong random generator (cryptography)

Exceptions

\Zend\Math\Exception\DomainException

Returns

string

 Properties

 

Alternative random byte generator using RandomLib

$generator : \RandomLib\Generator

Default

null
Static