artworld.js/artworld/random.js

24 lines
403 B
JavaScript
Raw Normal View History

2024-07-06 20:21:35 +00:00
export class Random {
static chance(odds) {
return Math.random() < odds;
}
2024-07-06 21:28:51 +00:00
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;
}
2024-07-07 05:38:41 +00:00
static choice(array) {
return array[Math.floor(Random.under(array.length))];
}
2024-07-06 20:21:35 +00:00
}