From 1d40399b9c234374c11b7896ae24fe4a9650a6c5 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Tue, 8 Apr 2014 16:22:52 +0200 Subject: [PATCH] hacky things D: --- src/pocketmine/utils/Random.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/pocketmine/utils/Random.php b/src/pocketmine/utils/Random.php index 26cc4858d..d4e8fd65e 100644 --- a/src/pocketmine/utils/Random.php +++ b/src/pocketmine/utils/Random.php @@ -68,9 +68,17 @@ class Random{ * @return int */ public function nextSignedInt(){ - $this->x ^= ($this->x << 16) & INT32_MASK; - $this->x ^= ($this->x >> 5) & INT32_MASK; - $this->x ^= ($this->x << 1) & INT32_MASK; + if(INT32_MASK === -1){ //32 bit, do hacky things to shift sign + $this->x ^= $this->x << 16; + $hasBit = $this->x < 1; + $t = ($hasBit === true ? $this->x ^ ~0x7fffffff : $this->x) >> 5; + $this->x ^= ($hasBit === true ? $t ^ ~0x7fffffff : $t); + $this->x ^= $this->x << 1; + }else{ //64 bit + $this->x ^= ($this->x << 16) & INT32_MASK; + $this->x ^= $this->x >> 5; + $this->x ^= ($this->x << 1) & INT32_MASK; + } $t = $this->x; $this->x = $this->y;