MikuMikuBeam/server/utils/randomUtils.js

22 lines
625 B
JavaScript

export function randomBoolean() {
return Math.random() < 0.5;
}
export function randomString(length) {
let result = "";
const characters =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
const charactersLength = characters.length;
for (let i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}
export function randomInteger(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
export function randomItem(array) {
return array[Math.floor(Math.random() * array.length)];
}