Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

fbRandom Class Reference

Inheritance diagram for fbRandom:

Inheritance graph
[legend]
List of all members.

Detailed Description

Random Number Generator (RNG) abstract class.

Random Number Generator (RNG) abstract class

Definition at line 24 of file Random.php.

Public Member Functions

 nextBase64String ($length=1)
 nextURL64String ($length=1)
 nextBase95String ($length=1)
 nextBoolean ()
 nextDouble ()
 nextGaussian ()
 nextInt ($min=null, $max=null)
 nextSalt ()
 nextPrintableString ($length=1)
 nextString ($length=1)
 nextBytes ($length=1)
 getSeed ()
 setSeed ($seed=null)
 getRandomSeed ()
 setRandomSeed ()

Static Public Member Functions

 isAvailable ()
 isBlocking ()
 isSeedable ()
getInstance ($blocking=null, $seed=null)
 getEntropy ()
 _getRandomByte ($modulo=0)
 _getRandomString ($length)

Private Attributes

 $_modulo_map
 $_seed = null


Member Function Documentation

fbRandom::_getRandomByte modulo = 0  )  [static]
 

Parameters:
$modulo int 0 thru 255
Returns:
int if $modulo == 0, return 0 thru 255, otherwise return 0 thru $modulo - 1

Reimplemented in fbRandom_DevRandom, fbRandom_GMP, fbRandom_LCG, fbRandom_MT_Rand, and fbRandom_Rand.

Definition at line 171 of file Random.php.

References _getRandomByte().

Referenced by _getRandomByte(), nextBoolean(), nextInt(), nextPrintableString(), and nextSalt().

fbRandom::_getRandomString length  )  [static]
 

Parameters:
$length int length of string
Returns:
string String of random characters of length $length

Reimplemented in fbRandom_DevRandom, fbRandom_GMP, fbRandom_LCG, fbRandom_MT_Rand, and fbRandom_Rand.

Definition at line 180 of file Random.php.

References _getRandomString().

Referenced by _getRandomString(), nextBase64String(), nextBytes(), nextDouble(), nextInt(), and nextURL64String().

fbRandom::getEntropy  )  [static]
 

Return a string of entropy

Returns:
string

Todo:
would implode('~', ...) be quicker?

Definition at line 114 of file Random.php.

& fbRandom::getInstance blocking = null,
seed = null
[static]
 

Definition at line 58 of file Random.php.

References fbRandom_DevUrandom::isAvailable(), fbRandom_DevRandom::isAvailable(), isAvailable(), and setSeed().

Referenced by fbHMAC_Login::_getChallenge().

fbRandom::getRandomSeed  ) 
 

Returns:
int a new random seed

Definition at line 526 of file Random.php.

Referenced by fbRandom_Rand::setSeed(), and fbRandom_MT_Rand::setSeed().

fbRandom::getSeed  ) 
 

Returns:
int the last seed passed to setSeed(), otherwise null

Definition at line 511 of file Random.php.

References $_seed.

fbRandom::isAvailable  )  [static]
 

Return if this random class is available or not

Returns:
bool true if this random class is available, otherwise false

Reimplemented in fbRandom_DevRandom, fbRandom_DevUrandom, and fbRandom_GMP.

Definition at line 31 of file Random.php.

fbRandom::isBlocking  )  [static]
 

Return if this random class blocks or not

Returns:
bool true if this random class blocks, otherwise false

Reimplemented in fbRandom_DevRandom.

Definition at line 41 of file Random.php.

fbRandom::isSeedable  )  [static]
 

Return if this random class is seedable or not

Returns:
bool true if this random class is seedable, otherwise false

Reimplemented in fbRandom_MT_Rand, and fbRandom_Rand.

Definition at line 51 of file Random.php.

fbRandom::nextBase64String length = 1  ) 
 

Parameters:
$length int
Returns:
string

Definition at line 188 of file Random.php.

References _getRandomString().

fbRandom::nextBase95String length = 1  ) 
 

Parameters:
$length int
Returns:
string

Definition at line 234 of file Random.php.

fbRandom::nextBoolean  ) 
 

Returns:
bool

Definition at line 249 of file Random.php.

References _getRandomByte().

fbRandom::nextBytes length = 1  ) 
 

Parameters:
$length int
Returns:
string a random string of length $length with ASCII NULs (0x00)

Definition at line 497 of file Random.php.

References _getRandomString().

fbRandom::nextDouble  ) 
 

Returns:
double >= 0.0 and < 1.0

Reimplemented in fbRandom_LCG.

Definition at line 256 of file Random.php.

References _getRandomString().

Referenced by nextGaussian().

fbRandom::nextGaussian  ) 
 

See also:
http://www.taygeta.com/random/gaussian.html
Returns:
double

Definition at line 310 of file Random.php.

References nextDouble().

fbRandom::nextInt min = null,
max = null
 

Parameters:
$min int
$max int
Returns:
int

Definition at line 338 of file Random.php.

References _getRandomByte(), _getRandomString(), and nextInt().

Referenced by nextInt().

fbRandom::nextPrintableString length = 1  ) 
 

Todo:
should the characters 128-159 be considered "printable"?
32-126, 160-255, 95 + 96 characters = 191 + 33 = 224 + 32 = 256

Parameters:
$length int
Returns:
string

Definition at line 457 of file Random.php.

References _getRandomByte().

fbRandom::nextSalt  ) 
 

Returns:
string

Definition at line 440 of file Random.php.

References _getRandomByte().

fbRandom::nextString length = 1  ) 
 

Parameters:
$length int
Returns:
string a random string of length $length without ASCII NULs (0x00)

Definition at line 481 of file Random.php.

fbRandom::nextURL64String length = 1  ) 
 

URL compatible Base64 encoding

This is how PHP encodes the session hash when session.hash_bits_per_character is set to '6' in php.ini

Parameters:
$length int
Returns:
string

Definition at line 214 of file Random.php.

References _getRandomString().

fbRandom::setRandomSeed  ) 
 

Returns:
bool true if this RNG is seedable, otherwise false

Definition at line 533 of file Random.php.

References setSeed().

fbRandom::setSeed seed = null  ) 
 

Parameters:
$seed mixed an integer of the new seed, or null to generate a new random seed
Returns:
bool true if this RNG is seedable, otherwise false

Reimplemented in fbRandom_MT_Rand, and fbRandom_Rand.

Definition at line 519 of file Random.php.

Referenced by getInstance(), and setRandomSeed().


Member Data Documentation

fbRandom::$_modulo_map [private]
 

Initial value:

 array(
//        0   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15
          0,  0,  1,  3,  3,  7,  7,  7,  7, 15, 15, 15, 15, 15, 15, 15,
         31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
         63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
         63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
        127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,
        127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,
        127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,
        127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,
        255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
        255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
        255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
        255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
        255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
        255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
        255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
        255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
    )

Definition at line 146 of file Random.php.

fbRandom::$_seed = null [private]
 

Definition at line 506 of file Random.php.

Referenced by getSeed().


The documentation for this class was generated from the following file:
Generated on Fri Mar 19 12:52:33 2004 for Freebeer by doxygen 1.3.6-20040222