aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/random.js23
1 files changed, 13 insertions, 10 deletions
diff --git a/lib/random.js b/lib/random.js
index 70bcaf04..5606622c 100644
--- a/lib/random.js
+++ b/lib/random.js
@@ -11,11 +11,7 @@ var random = {
};
}
- options = options || {
- min: 0,
- max: 1,
- precision: 1
- };
+ options = options || {};
if (typeof options.min === "undefined") {
options.min = 0;
@@ -24,13 +20,20 @@ var random = {
if (typeof options.max === "undefined") {
options.max = 1;
}
-
- // by incrementing max by 1, max becomes inclusive of the range
- if (options.max > 0) {
- options.max++;
+ if (typeof options.precision === "undefined") {
+ options.precision = 1;
}
- var randomNumber = mersenne.rand(options.max, options.min);
+ // Make the range inclusive of the max value
+ var max = options.max;
+ if (max > 0) {
+ max += options.precision;
+ }
+
+ var randomNumber = Math.floor(options.precision *
+ mersenne.rand(max / options.precision,
+ options.min / options.precision)
+ );
return randomNumber;
},