nowjs-core
Version:
NowCanDo Javascript Core [nowjs-core] is a library written by TypeScript code maintains under Apache 2.0 licence
38 lines (37 loc) • 1.07 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.randomBytes = (length) => {
const window = globalThis || {};
if (window.crypto || window.msCrypto) {
const r = new Uint32Array(length);
window.crypto.getRandomValues(r);
return r;
}
else {
if (process && process.env) {
const crypto = require('crypto');
return crypto.randomBytes(length);
}
else {
const r = [];
for (let ix = 0; ix < length; ix++) {
r.push(Math.floor(Math.random() * 255));
}
return r;
}
}
};
function secureMathRandom() {
return exports.randomBytes(1)[0] / 4294967295;
}
exports.secureMathRandom = secureMathRandom;
function random(min, max) {
return Math.random() * (max - min + 1) + min;
}
exports.random = random;
function randomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
exports.randomInt = randomInt;