reign
Version:
A persistent, typed-objects implementation.
42 lines (35 loc) • 888 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = random;
exports.ascii = ascii;
function random() {
return Math.random() > 0.7 ? multibyte() : ascii();
}
function ascii() {
const length = Math.floor(Math.random() * 255);
const chars = new Array(length);
let seed = Math.round(Math.random() * 100000);
for (let i = 0; i < length; i++) {
seed = (seed + i * 333) % 127;
if (seed < 32) {
seed += 32;
}
chars[i] = seed;
}
return String.fromCharCode(...chars);
}
function multibyte() {
const length = Math.floor(Math.random() * 255);
const chars = new Array(length);
let seed = Math.round(Math.random() * 100000);
for (let i = 0; i < length; i++) {
seed = (seed + i * 333) % 512;
if (seed < 32) {
seed += 32;
}
chars[i] = seed;
}
return String.fromCharCode(...chars);
}