reign
Version:
A persistent, typed-objects implementation.
42 lines (35 loc) • 902 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() {
var length = Math.floor(Math.random() * 255);
var chars = new Array(length);
var seed = Math.round(Math.random() * 100000);
for (var i = 0; i < length; i++) {
seed = (seed + i * 333) % 127;
if (seed < 32) {
seed += 32;
}
chars[i] = seed;
}
return String.fromCharCode.apply(String, chars);
}
function multibyte() {
var length = Math.floor(Math.random() * 255);
var chars = new Array(length);
var seed = Math.round(Math.random() * 100000);
for (var i = 0; i < length; i++) {
seed = (seed + i * 333) % 512;
if (seed < 32) {
seed += 32;
}
chars[i] = seed;
}
return String.fromCharCode.apply(String, chars);
}