octo-deno/make/numbers.js

58 lines
1.6 KiB
JavaScript
Raw Normal View History

2017-04-22 20:16:47 +00:00
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
2017-04-12 18:43:55 +00:00
make.numbers = {
bool: function () {
return random.bool();
},
float: function () {
let n;
if (random.chance(32)) {
2017-04-22 20:07:29 +00:00
switch (random.number(4)) {
case 0:
n = random.range(Number.MAX_VALUE, Number.MIN_VALUE);
break;
case 1:
n = Math.pow(10, 1) / Math.pow(10, random.number(307));
break;
case 2:
n = Math.pow(2, random.float() * random.float() * 64);
break;
case 3:
n = Math.pow(10, random.range(1, 9)) / Math.pow(10, random.range(1, 9));
break;
2017-04-12 18:43:55 +00:00
}
return n;
}
switch (random.number(6)) {
2017-04-22 20:07:29 +00:00
default:
n = random.float();
2017-04-12 18:43:55 +00:00
}
return n;
},
rangeNumber: function () {
2017-04-22 19:02:38 +00:00
return random.pick([1, 2, 3, 4, 6, 8, 16, 32, 64, make.numbers.tinyNumber]);
2017-04-12 18:43:55 +00:00
},
tinyNumber: function () {
return Math.pow(2, random.number(12));
},
unsignedNumber: function () {
if (random.chance(2)) {
2017-04-22 19:02:38 +00:00
return Math.abs(make.numbers.number());
2017-04-12 18:43:55 +00:00
}
return Math.pow(2, random.number(65)) + random.number(3) - 1;
},
evenNumber: function (number) {
return number % 2 == 1 ? ++number : number;
},
number: function () {
2017-04-13 02:14:02 +00:00
let value = random.choose([
2017-04-22 19:02:38 +00:00
[10, make.numbers.float],
[10, [make.numbers.rangeNumber, make.numbers.tinyNumber]],
2017-04-22 20:07:29 +00:00
[1, Make.numbers.unsignedNumber]
2017-04-12 18:43:55 +00:00
]);
return random.chance(10) ? -value : value;
}
2017-04-13 02:14:02 +00:00
};