voided-data
Version:
Proper DS for TS
34 lines (33 loc) • 847 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.randomSfc32 = exports.sfc32 = void 0;
const hash_1 = require("./hash");
/**
* @param a: seed part 1
* @param b: seed part 1
* @param c: seed part 1
* @param d: seed part 1
*/
function sfc32(a, b, c, d) {
a >>>= 0;
b >>>= 0;
c >>>= 0;
d >>>= 0;
let t = (a + b) | 0;
return function () {
t = (a + b) | 0;
a = b ^ (b >>> 9);
b = (c + (c << 3)) | 0;
c = (c << 21) | (c >>> 11);
d = (d + 1) | 0;
t = (t + d) | 0;
c = (c + t) | 0;
return (t >>> 0) / 4294967296;
};
}
exports.sfc32 = sfc32;
function randomSfc32(seed) {
const [a, b, c, d] = (0, hash_1.cyrb128)(seed);
return sfc32(a, b, c, d);
}
exports.randomSfc32 = randomSfc32;