From 26772082da273b1d1ae401add7463a3ac6e1a3e0 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Tue, 11 Feb 2014 22:28:53 +0100 Subject: [PATCH] Random generator with signed int/float methods --- src/utils/Random.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/utils/Random.php b/src/utils/Random.php index fd0273ecb..fbd00397f 100644 --- a/src/utils/Random.php +++ b/src/utils/Random.php @@ -47,10 +47,18 @@ class Random{ return Utils::readInt($this->nextBytes(4)) & 0x7FFFFFFF; } + public function nextSignedInt(){ + return Utils::readInt($this->nextBytes(4)); + } + public function nextFloat(){ return $this->nextInt() / 0x7FFFFFFF; } + public function nextSignedFloat(){ + return $this->nextSignedInt() / 0x7FFFFFFF; + } + public function nextBytes($byteCount){ $bytes = ""; for($i = 0; $i < $byteCount; ++$i){