Zend Framework  3.0
Static Public Member Functions | Static Protected Attributes | List of all members
Rand Class Reference

Pseudorandom number generator (PRNG) More...

Static Public Member Functions

static getBytes ($length)
 Generate random bytes using different approaches If PHP 7 is running we use the random_bytes() function.
 
static getBoolean ()
 Generate random boolean.
 
static getInteger ($min, $max)
 Generate a random integer between $min and $max.
 
static getFloat ()
 Generate random float (0..1) This function generates floats with platform-dependent precision.
 
static getString ($length, $charlist=null)
 Generate a random string of specified length.
 

Static Protected Attributes

static $generator = null
 

Detailed Description

Pseudorandom number generator (PRNG)

Member Function Documentation

static getBoolean ( )
static

Generate random boolean.

Returns
bool
static getBytes (   $length)
static

Generate random bytes using different approaches If PHP 7 is running we use the random_bytes() function.

Parameters
int$length
Returns
string
Exceptions
Exception\RuntimeException
static getFloat ( )
static

Generate random float (0..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.

Returns
float
static getInteger (   $min,
  $max 
)
static

Generate a random integer between $min and $max.

Parameters
int$min
int$max
Returns
int
Exceptions
Exception\DomainException
static getString (   $length,
  $charlist = null 
)
static

Generate a random string of specified length.

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

Parameters
int$length
string | null$charlist
Returns
string
Exceptions
Exception\DomainException

Member Data Documentation

$generator = null
staticprotected