artworld.js/artworld/random.js
2024-07-07 00:38:41 -05:00

24 lines
403 B
JavaScript

export class Random {
static chance(odds) {
return Math.random() < odds;
}
static under(num) {
let n = Math.random() * num;
return n;
}
static between(lo, hi) {
let n = Math.random() * (hi - lo) + lo;
return n;
}
static radians() {
return Math.random() * Math.PI * 2;
}
static choice(array) {
return array[Math.floor(Random.under(array.length))];
}
}