diff --git a/src/pocketmine/PocketMine.php b/src/pocketmine/PocketMine.php index 1ac03c500..485ba1ace 100644 --- a/src/pocketmine/PocketMine.php +++ b/src/pocketmine/PocketMine.php @@ -360,6 +360,7 @@ namespace pocketmine { } @define("ENDIANNESS", (pack("d", 1) === "\77\360\0\0\0\0\0\0" ? Binary::BIG_ENDIAN : Binary::LITTLE_ENDIAN)); + @define("INT32_MASK", is_int(0xffffffff) ? 0xffffffff : -1); @ini_set("opcache.mmap_base", bin2hex(Utils::getRandomBytes(8, false))); //Fix OPCache address errors if(!file_exists(\pocketmine\DATA . "server.properties") and !isset($opts["no-wizard"])){ diff --git a/src/pocketmine/utils/Random.php b/src/pocketmine/utils/Random.php index 8184cecb0..26cc4858d 100644 --- a/src/pocketmine/utils/Random.php +++ b/src/pocketmine/utils/Random.php @@ -48,9 +48,9 @@ class Random{ */ public function setSeed($seed){ $seed = crc32($seed); - $this->x = ($seed ^ 9876543210) % 0x7fffffff; - $this->z = ($seed ^ -123456789) % 0x7fffffff; - $this->y = ($seed ^ 1122334455) % 0x7fffffff; + $this->x = ($seed ^ 1076543210) & INT32_MASK; + $this->z = ($seed ^ 0xdeadc0de) & INT32_MASK; + $this->y = ($seed ^ 1122334455) & INT32_MASK; } /** @@ -68,9 +68,9 @@ class Random{ * @return int */ public function nextSignedInt(){ - $this->x ^= ($this->x << 16) & 0xffffffff; - $this->x ^= ($this->x >> 5) & 0xffffffff; - $this->x ^= ($this->x << 1) & 0xffffffff; + $this->x ^= ($this->x << 16) & INT32_MASK; + $this->x ^= ($this->x >> 5) & INT32_MASK; + $this->x ^= ($this->x << 1) & INT32_MASK; $t = $this->x; $this->x = $this->y; @@ -82,7 +82,7 @@ class Random{ if($t > 2147483647){ $t -= 4294967296; } - return (int) $t % 0x7fffffff; + return (int) $t; } /**