X-Git-Url: https://git.mxchange.org/?p=core.git;a=blobdiff_plain;f=inc%2Fclasses%2Fmain%2Frng%2Fclass_RandomNumberGenerator.php;h=6b26fe848510cbd30a320ce818efae737ad85214;hp=bc8c42d46a097da8fc2efea087b33b6ebd9f191e;hb=f2b317c7477adb9912dca424bd86fa5b238d9674;hpb=ca915ca6e0366d10ffe557822a891f16c6b2171e diff --git a/inc/classes/main/rng/class_RandomNumberGenerator.php b/inc/classes/main/rng/class_RandomNumberGenerator.php index bc8c42d4..6b26fe84 100644 --- a/inc/classes/main/rng/class_RandomNumberGenerator.php +++ b/inc/classes/main/rng/class_RandomNumberGenerator.php @@ -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;