noise generator (test fandom foo)
HTML
<div id="target"></div>
CSS
body {
height: 100vh;
width: 100vw;
box-sizing: border-box;
display: flex;
justify-content: center;
align-items: center;
}
JavaScript
// ГПСЧ на основе алгоритма XXHASH
class Rerandom {
constructor(seed=0){
this.seed = seed;
this.p1 = 2654435761;
this.p2 = 2246822519;
this.p3 = 3266489917;
this.p4 = 668265263;
this.p5 = 374761393;
this.p=[this.p1,this.p2,this.p3,this.p4,this.p5];
this.cut = 4294967295;
this.random = this._GetXxHash;
this.count = 0;
}
_RotateLeft(value, count) {
return (value << count) | (value >>> (32 - count));
}
_CalcSubHash(value, read_value) {
value += read_value * this.p2;
value = this._RotateLeft (value, 13);
value *= this.p1;
return value;
}
_GetXxHash(...buf) {
let h32;
let index = 0;
let len = buf.length;
if (len >= 4) {
let limit = len - 4;
let v1 = this.seed + this.p1 + this.p2;
let v2 = this.seed + this.p2;
let v3 = this.seed + 0;
let v4 = this.seed - this.p1;
while (index <= limit) {
v1 = this._CalcSubHash (v1, buf[index]);
index++;
v2 = this._CalcSubHash (v2, buf[index]);
index++;
v3 = this._CalcSubHash (v3, buf[index]);
index++;
v4 = this._CalcSubHash (v4, buf[index]);
index++;
}
h32 = this._RotateLeft (v1, 1) + this._RotateLeft (v2, 7) + this._RotateLeft (v3, 12) + this._RotateLeft (v4, 18);
}
else {
h32 = this.seed + this.p5;
}
h32 += len * 4;
while (index < len) {
h32 += buf[index] * this.p3;
h32 = this._RotateLeft (h32, 17) * this.p4;
index++;
}
h32 ^= h32 >>> 15;
h32 *= this.p2;
h32 ^= h32 >>> 13;
h32 *= this.p3;
h32 ^= h32 >>> 16;
return (h32>>>0)/4294967295.0;
}
next() {
var r = this._GetXxHash(this.count)
this.count ++;
return r;
}
}
// инициализируем ГПСЧ
const seed = 5;
const R = new Rerandom(seed);
// Далее ваш код
const target = document.querySelector( '#target' );
/* const randomFoo = () => Math.random(); */
const randomFoo = () => R.next();
testRandomFoo({
foo: randomFoo,
sizeX: 400,
sizeY: 400,
target,
rgb: [0, 0, 0]
});
function testRandomFoo({
foo = () =>...