avocado-old/packages/math/range.js

34 lines
589 B
JavaScript
Raw Normal View History

2019-11-03 10:40:08 -06:00
import {randomNumber} from './math';
export class Range {
constructor(jsonOrValue) {
if ('undefined' === typeof jsonOrValue.min) {
this.min = jsonOrValue;
}
else {
this.min = jsonOrValue.min;
this.max = jsonOrValue.max;
}
}
static value(rangeOrOther) {
if (rangeOrOther instanceof Range) {
return rangeOrOther.value();
}
else {
return rangeOrOther;
}
}
value() {
if ('undefined' === typeof this.max) {
return this.min;
}
else {
return randomNumber(this.min, this.max, false);
}
}
}