Comparing version 0.1.1 to 0.2.0
@@ -33,3 +33,3 @@ 'use strict'; | ||
value: function inRange(min, max) { | ||
return Math.round(Math.random() * (max - min) + min); | ||
return Math.floor(Math.random() * (max - min + 1) + min); | ||
} | ||
@@ -64,2 +64,16 @@ | ||
} | ||
/** | ||
* Check to see if a given percent chance occurs | ||
* @param {number} percentChance a 0-100 number representing % success chance | ||
* @return {boolean} | ||
*/ | ||
}, { | ||
key: 'probability', | ||
value: function probability(percentChance) { | ||
var rand = Math.random(); | ||
var target = percentChance / 100; | ||
return target >= rand; | ||
} | ||
}]); | ||
@@ -66,0 +80,0 @@ |
@@ -1,2 +0,2 @@ | ||
"use strict";function _classCallCheck(n,e){if(!(n instanceof e))throw new TypeError("Cannot call a class as a function")}var _createClass=function(){function n(n,e){for(var r=0;r<e.length;r++){var a=e[r];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(n,a.key,a)}}return function(e,r,a){return r&&n(e.prototype,r),a&&n(e,a),e}}(),Random=function(){function n(){_classCallCheck(this,n)}return _createClass(n,null,[{key:"coinFlip",value:function(){return Math.round(Math.random())}},{key:"inRange",value:function(n,e){return Math.round(Math.random()*(e-n)+n)}},{key:"fromArray",value:function(n){return n[Math.floor(Math.random()*n.length)]}},{key:"roll",value:function(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:20;return n*(Math.floor(e*Math.random())+1)}}]),n}();exports.Random=Random; | ||
"use strict";function _classCallCheck(n,r){if(!(n instanceof r))throw new TypeError("Cannot call a class as a function")}var _createClass=function(){function n(n,r){for(var a=0;a<r.length;a++){var e=r[a];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(n,e.key,e)}}return function(r,a,e){return a&&n(r.prototype,a),e&&n(r,e),r}}(),Random=function(){function n(){_classCallCheck(this,n)}return _createClass(n,null,[{key:"coinFlip",value:function(){return Math.round(Math.random())}},{key:"inRange",value:function(n,r){return Math.floor(Math.random()*(r-n+1)+n)}},{key:"fromArray",value:function(n){return n[Math.floor(Math.random()*n.length)]}},{key:"roll",value:function(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:20;return n*(Math.floor(r*Math.random())+1)}},{key:"probability",value:function(n){return n/100>=Math.random()}}]),n}();exports.Random=Random; | ||
//# sourceMappingURL=dist/rando.min.js.map |
{ | ||
"name": "rando-js", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "Randomization utilities for NodeJS in es6", | ||
"main": "rando.js", | ||
"devDependencies": { | ||
"devDependencies": { | ||
"babel-cli": "^6.11.4", | ||
@@ -8,0 +8,0 @@ "babel-preset-es2015": "^6.9.0", |
18
rando.js
@@ -19,3 +19,3 @@ 'use strict'; | ||
static inRange(min, max) { | ||
return Math.round(Math.random() * (max - min) + min); | ||
return Math.floor(Math.random() * (max - min + 1) + min); | ||
} | ||
@@ -38,9 +38,19 @@ | ||
*/ | ||
static roll(dice = 1, sides = 20) { | ||
return dice * (Math.floor(sides * Math.random()) + 1); | ||
const rolls = Array.from({length: dice}, () => Math.floor(sides * Math.random()) + 1); | ||
return rolls.reduce((acc, roll) => acc + roll, 0); | ||
} | ||
/** | ||
* Check to see if a given percent chance occurs | ||
* @param {number} percentChance a 0-100 number representing % success chance | ||
* @return {boolean} | ||
*/ | ||
static probability(percentChance) { | ||
const rand = Math.random(); | ||
const target = percentChance / 100; | ||
return target >= rand; | ||
} | ||
} | ||
exports.Random = Random; | ||
exports.Random = Random; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9543
117
8