Ivan - Fix linear congruential generator
This commit is contained in:
parent
84b128326c
commit
aa533856d5
|
@ -30,8 +30,8 @@ class Hashing {
|
||||||
$sqrt = sqrt($number);
|
$sqrt = sqrt($number);
|
||||||
$prime = true;
|
$prime = true;
|
||||||
|
|
||||||
for($i = 0; $i < $sqrt; $i++) {
|
for($i = 2; $i <= $sqrt; $i++) {
|
||||||
if($sqrt % 2 === 0) {
|
if($number % $i === 0) {
|
||||||
$prime = false;
|
$prime = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,8 +21,10 @@ class LinearCongruentialGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function generate($offset) {
|
public function generate($offset) {
|
||||||
if($offset) return ($this->first - $this->min + $offset * $this->gap) % ($this->max - $this->min + 1) + $this->min;
|
if(!$this->first) throw new Exception('LinearCongruentialGenerator: first is not set');
|
||||||
else return $this->generateFirst();
|
if(!$this->gap) throw new Exception('LinearCongruentialGenerator: gap is not set');
|
||||||
|
|
||||||
|
return ($this->first - $this->min + $offset * $this->gap) % ($this->max - $this->min + 1) + $this->min;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function generateFirst() {
|
public function generateFirst() {
|
||||||
|
|
Loading…
Reference in New Issue