2019-08-20 17:59:26 +02:00
|
|
|
function rand(min, max) {
|
2020-01-17 21:11:15 +01:00
|
|
|
return Math.floor(randf(min, max));
|
|
|
|
}
|
|
|
|
|
|
|
|
function randf(min, max) {
|
|
|
|
if (max == null) {
|
|
|
|
max = min || 1;
|
|
|
|
min = 0;
|
2019-08-20 17:59:26 +02:00
|
|
|
}
|
2020-01-17 21:11:15 +01:00
|
|
|
return Math.random() * (max - min) + min;
|
|
|
|
}
|
|
|
|
|
|
|
|
function randOneFrom(items) {
|
|
|
|
return items[rand(items.length)];
|
|
|
|
}
|
|
|
|
|
|
|
|
function randOneIn(max = 2) {
|
|
|
|
return rand(0, max) === 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default {
|
|
|
|
rand,
|
|
|
|
randf,
|
|
|
|
randOneFrom,
|
|
|
|
randOneIn
|
|
|
|
};
|