Example #1
0
 function &getInstance($blocking = null, $seed = null)
 {
     static $instances;
     if (!isset($instances)) {
         $instances = array();
     }
     $signature = serialize(array($blocking, $seed));
     if (!array_key_exists($signature, $instances)) {
         do {
             if (is_null($seed)) {
                 if (preg_match('/^win/i', PHP_OS)) {
                     include_once FREEBEER_BASE . '/lib/Random/Win32.php';
                     if (fbRandom_Win32::isAvailable()) {
                         $classname = 'fbRandom_Win32';
                         break;
                     }
                 } else {
                     if ($blocking) {
                         include_once FREEBEER_BASE . '/lib/Random/DevRandom.php';
                         if (fbRandom_DevRandom::isAvailable()) {
                             $classname = 'fbRandom_DevRandom';
                             break;
                         }
                     }
                     include_once FREEBEER_BASE . '/lib/Random/DevUrandom.php';
                     if (fbRandom_DevUrandom::isAvailable()) {
                         $classname = 'fbRandom_DevUrandom';
                         break;
                     }
                 }
             }
             include_once FREEBEER_BASE . '/lib/Random/MT_Rand.php';
             $classname = 'fbRandom_MT_Rand';
         } while (false);
         $instances[$signature] = new $classname($seed);
         if (!is_null($seed)) {
             $instance =& $instances[$signature];
             $instance->setSeed($seed);
         }
     }
     return $instances[$signature];
 }
 function isAvailable()
 {
     return fbRandom_DevUrandom::isAvailable();
 }