You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
19 lines
563 B
19 lines
563 B
2 years ago
|
// General helper functions
|
||
|
|
||
|
// Returns a random int between min and max (inclusive)
|
||
|
function randomInt(min, max) {
|
||
|
min = Math.ceil(min);
|
||
|
max = Math.floor(max);
|
||
|
return Math.floor(Math.random() * (max - min + 1)) + min;
|
||
|
}
|
||
|
|
||
|
// Returns a random item from the given array
|
||
|
export function selectRandom(arrayToChooseFrom) {
|
||
|
return arrayToChooseFrom[randomInt(0, arrayToChooseFrom.length - 1)]
|
||
|
}
|
||
|
|
||
|
// Waits for the given number of milliseconds (or a brief pause by default)
|
||
|
export function sleep(ms = 550) {
|
||
|
return new Promise((r) => setTimeout(r, ms))
|
||
|
}
|