Add range generator for floating points

This commit is contained in:
Christoph Diehl 2018-01-16 18:39:48 +01:00
parent bbca3019aa
commit ab97313acb

View file

@ -34,6 +34,14 @@ make.number = {
range: function () { range: function () {
return random.pick([1, 2, 3, 4, 6, 8, 16, 32, 64, make.number.tiny]) return random.pick([1, 2, 3, 4, 6, 8, 16, 32, 64, make.number.tiny])
}, },
frange: function (min, max, precision) {
let x = Math.random() * (min - max) + max
if (precision) {
let power = Math.pow(10, precision || 0)
x = Math.round(x * power) / power
}
return x
},
tiny: function () { tiny: function () {
return Math.pow(2, random.number(12)) return Math.pow(2, random.number(12))
}, },