asdf-games/lib/utilities/math.js

26 lines
395 B
JavaScript
Raw Normal View History

function rand(min, max) {
return Math.floor(randf(min, max));
}
function randf(min, max) {
if (max == null) {
max = min || 1;
min = 0;
}
return Math.random() * (max - min) + min;
}
function randOneFrom(items) {
return items[rand(items.length)];
}
function randOneIn(max = 2) {
return rand(0, max) === 0;
}
2020-02-29 13:45:56 +01:00
module.exports = {
rand,
randf,
randOneFrom,
randOneIn
};