Rewrites
[core.git] / inc / classes / main / rng / class_RandomNumberGenerator.php
index bc8c42d46a097da8fc2efea087b33b6ebd9f191e..6b26fe848510cbd30a320ce818efae737ad85214 100644 (file)
@@ -47,6 +47,11 @@ class RandomNumberGenerator extends BaseFrameworkSystem {
         */
        private $rndStrLen = 0;
 
+       /**
+        * Self instance
+        */
+       private static $selfInstance = NULL;
+
        /**
         * Protected constructor
         *
@@ -65,11 +70,20 @@ class RandomNumberGenerator extends BaseFrameworkSystem {
         * @return      $rngInstance    An instance of this random number generator
         */
        public static final function createRandomNumberGenerator (FrameworkInterface $extraInstance = NULL) {
-               // Get a new instance
-               $rngInstance = new RandomNumberGenerator();
+               // Is self instance set?
+               if (is_null(self::$selfInstance)) {
+                       // Get a new instance
+                       $rngInstance = new RandomNumberGenerator();
 
-               // Initialize the RNG now
-               $rngInstance->initRng($extraInstance);
+                       // Initialize the RNG now
+                       $rngInstance->initRng($extraInstance);
+
+                       // Set it "self"
+                       self::$selfInstance = $rngInstance;
+               } else {
+                       // Use from self instance
+                       $rngInstance = self::$selfInstance;
+               }
 
                // Return the instance
                return $rngInstance;