mirror of
https://github.com/opensupports/opensupports.git
synced 2025-07-27 07:44:29 +02:00
Ivan - Fix linear congruential generator
This commit is contained in:
parent
84b128326c
commit
aa533856d5
@ -30,8 +30,8 @@ class Hashing {
|
||||
$sqrt = sqrt($number);
|
||||
$prime = true;
|
||||
|
||||
for($i = 0; $i < $sqrt; $i++) {
|
||||
if($sqrt % 2 === 0) {
|
||||
for($i = 2; $i <= $sqrt; $i++) {
|
||||
if($number % $i === 0) {
|
||||
$prime = false;
|
||||
break;
|
||||
}
|
||||
|
@ -21,8 +21,10 @@ class LinearCongruentialGenerator {
|
||||
}
|
||||
|
||||
public function generate($offset) {
|
||||
if($offset) return ($this->first - $this->min + $offset * $this->gap) % ($this->max - $this->min + 1) + $this->min;
|
||||
else return $this->generateFirst();
|
||||
if(!$this->first) throw new Exception('LinearCongruentialGenerator: first is not set');
|
||||
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() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user