X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Fclasses%2Fmain%2Frng%2Fclass_RandomNumberGenerator.php;h=ec44b9025698e713e04fa770d6afec41fecce647;hb=95fc70ab8370c843a574ef70af1a5486997ec89a;hp=c92c6bccf0e12954488aa44e11d9e9d58243ba46;hpb=3e1fbf30a631cf1cd64562b69228452c49e0033f;p=core.git diff --git a/inc/classes/main/rng/class_RandomNumberGenerator.php b/inc/classes/main/rng/class_RandomNumberGenerator.php index c92c6bcc..ec44b902 100644 --- a/inc/classes/main/rng/class_RandomNumberGenerator.php +++ b/inc/classes/main/rng/class_RandomNumberGenerator.php @@ -2,11 +2,11 @@ /** * A standard random number generator * - * @author Roland Haeder + * @author Roland Haeder * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Core Developer Team + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2013 Core Developer Team * @license GNU GPL 3.0 or any newer version - * @link http://www.ship-simu.org + * @link http://www.shipsimu.org * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -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; @@ -91,7 +105,7 @@ class RandomNumberGenerator extends BaseFrameworkSystem { $this->extraNumber = ($this->prime * $this->prime / pow(pi(), 2)); // Seed mt_rand() - mt_srand((double) sqrt(microtime() * 100000000 * $this->extraNumber)); + mt_srand((double) sqrt(microtime(TRUE) * 100000000 * $this->extraNumber)); // Set the server IP to cluster $serverIp = 'cluster';