image-in-browser
Version:
Package for encoding / decoding images, transforming images, applying filters, drawing primitives on images on the client side (no need for server Node.js)
33 lines • 851 B
JavaScript
export class RandomUtils {
static crand() {
return 1 - 2 * Math.random();
}
static grand() {
let x1 = 0;
let w = 0;
do {
const x2 = 2 * Math.random() - 1;
x1 = 2 * Math.random() - 1;
w = x1 * x1 + x2 * x2;
} while (w <= 0 || w >= 1);
return x1 * Math.sqrt((-2 * Math.log(w)) / w);
}
static prand(z) {
if (z <= 1e-10) {
return 0;
}
if (z > 100) {
return Math.trunc(Math.sqrt(z) * RandomUtils.grand() + z);
}
let k = 0;
const y = Math.exp(-z);
for (let s = 1.0; s >= y; ++k) {
s *= Math.random();
}
return k - 1;
}
static intrand(max) {
return Math.floor(Math.random() * max);
}
}
//# sourceMappingURL=random-utils.js.map