예제 #1
0
파일: Random.php 프로젝트: Artea/freebeer
 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];
 }
예제 #2
0
 function isAvailable()
 {
     return fbRandom_Win32::isAvailable();
 }