X-Git-Url: https://git.mxchange.org/?p=core.git;a=blobdiff_plain;f=inc%2Fclasses%2Fmain%2Frng%2Fclass_RandomNumberGenerator.php;h=fb74071e3931f5cb57ec2ff386960ad4fe8dd658;hp=0580b87db376c9b974aac8e367d50addadd72908;hb=d26e71af1e28dc1429823bdec244df6303f9b2fb;hpb=fc5010729854b1f9c9bc60249460d092ea6694b6 diff --git a/inc/classes/main/rng/class_RandomNumberGenerator.php b/inc/classes/main/rng/class_RandomNumberGenerator.php index 0580b87d..fb74071e 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 - 2015 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(true) * 100000000 * $this->extraNumber)); + mt_srand((double) sqrt(microtime(TRUE) * 100000000 * $this->extraNumber)); // Set the server IP to cluster $serverIp = 'cluster';