Zend Framework  2.4
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, $strong=false)
 Generate random bytes using OpenSSL or Mcrypt and mt_rand() as fallback.
 
static getAlternativeGenerator ()
 Retrieve a fallback/alternative RNG generator.
 
static getBoolean ($strong=false)
 Generate random boolean.
 
static getInteger ($min, $max, $strong=false)
 Generate a random integer between $min and $max.
 
static getFloat ($strong=false)
 Generate random float (0..1) This function generates floats with platform-dependent precision.
 
static getString ($length, $charlist=null, $strong=false)
 Generate a random string of specified length.
 

Static Protected Attributes

static $generator = null
 

Detailed Description

Pseudorandom number generator (PRNG)

Member Function Documentation

static getAlternativeGenerator ( )
static

Retrieve a fallback/alternative RNG generator.

Returns
RandomLib
static getBoolean (   $strong = false)
static

Generate random boolean.

Parameters
bool$strongtrue if you need a strong random generator (cryptography)
Returns
bool
static getBytes (   $length,
  $strong = false 
)
static

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

Parameters
int$length
bool$strongtrue if you need a strong random generator (cryptography)
Returns
string
Exceptions
Exception\RuntimeException
static getFloat (   $strong = false)
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.

Parameters
bool$strongtrue if you need a strong random generator (cryptography)
Returns
float
static getInteger (   $min,
  $max,
  $strong = false 
)
static

Generate a random integer between $min and $max.

Parameters
int$min
int$max
bool$strongtrue if you need a strong random generator (cryptography)
Returns
int
Exceptions
Exception\DomainException
static getString (   $length,
  $charlist = null,
  $strong = false 
)
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
bool$strongtrue if you need a strong random generator (cryptography)
Returns
string
Exceptions
Exception\DomainException

Member Data Documentation

$generator = null
staticprotected