Removed obsolete Java Random

This commit is contained in:
Shoghi Cervantes 2014-01-28 11:25:12 +01:00
parent 4aa7b3eaf8
commit 439c0e8280

View File

@ -64,57 +64,3 @@ class Java_String{
return $h;
}
}
class Java_Random{
private $haveNextNextGaussian, $nextNextGaussian, $seed, $n1, $n2, $n3, $zero;
public function __construct($seed = false){
$this->n1 = new Math_BigInteger(0x5DEECE66D);
$this->n2 = new Math_BigInteger(1);
$this->n2 = $this->n2->bitwise_leftShift(48)->subtract($this->n2);
$this->n3 = new Math_BigInteger(0xB);
$this->zero = new Math_BigInteger(0);
if($seed === false){
$seed = microtime(true) * 1000000;
}
$this->setSeed($seed);
}
public function setSeed($seed){
$seed = new Math_BigInteger($seed);
$this->seed = $seed->bitwise_xor($this->n1)->bitwise_and($this->n2);
$this->haveNextNextGaussian = false;
}
protected function next($bits){
$bits = (int) $bits;
$this->seed = $this->seed->multiply($this->n1)->add($this->n3)->bitwise_and($this->n2);
return $this->_tripleRightShift($this->seed, (48 - $bits));
}
private function _tripleRightShift($number, $places){
if($number->compare($this->zero) >= 0){
return $number->bitwise_rightShift($places);
}
$n1 = new Math_BigInteger(2);
return $number->bitwise_rightShift($places)->add($n1->bitwise_leftShift(~$places));
}
public function nextBytes($bytes){
$bytes = (int) $bytes;
$b = b"";
$max = $bytes & ~0x3;
for($i = 0; $i < $max; $i += 4){
$b .= $this->next(32)->toBytes();
}
if($max < $bytes){
$random = $this->next(32)->toBytes();
for($j = $max; $j < $bytes; ++$j){
$b .= $random{$j-$max};
}
}
return $b;
}
}