Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rando-js

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rando-js - npm Package Compare versions

Comparing version 0.1.1 to 0.2.0

16

dist/rando.js

@@ -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 @@

2

dist/rando.min.js

@@ -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",

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc