Add range generator for floating points
This commit is contained in:
parent
bbca3019aa
commit
ab97313acb
1 changed files with 8 additions and 0 deletions
|
@ -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))
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue