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

d3-random

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

d3-random - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

.eslintrc

2

build/bundle.js

@@ -1,1 +0,1 @@

var version = "0.2.0"; export * from "../index"; export {version};
var version = "0.2.1"; export * from "../index"; export {version};
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define('d3-random', ['exports'], factory) :
factory((global.d3_random = {}));
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.d3_random = {})));
}(this, function (exports) { 'use strict';
function uniform(min, max) {
var n = arguments.length;
if (!n) min = 0, max = 1;
else if (n === 1) max = +min, min = 0;
else min = +min, max = +max - min;
min = min == null ? 0 : +min;
max = max == null ? 1 : +max;
if (arguments.length === 1) max = min, min = 0;
else max -= min;
return function() {
return Math.random() * max + min;
};
};
}
function normal(mu, sigma) {
var n = arguments.length;
if (!n) mu = 0, sigma = 1;
else if (n === 1) mu = +mu, sigma = 1;
else mu = +mu, sigma = +sigma;
var x, r;
mu = mu == null ? 0 : +mu;
sigma = sigma == null ? 1 : +sigma;
return function() {
var x, y, r;
do {
var y;
// If available, use the second previously-generated uniform random.
if (x != null) y = x, x = null;
// Otherwise, generate a new x and y.
else do {
x = Math.random() * 2 - 1;

@@ -29,5 +33,6 @@ y = Math.random() * 2 - 1;

} while (!r || r > 1);
return mu + sigma * x * Math.sqrt(-2 * Math.log(r) / r);
return mu + sigma * y * Math.sqrt(-2 * Math.log(r) / r);
};
};
}

@@ -39,3 +44,3 @@ function logNormal() {

};
};
}

@@ -47,3 +52,3 @@ function irwinHall(n) {

};
};
}

@@ -55,3 +60,3 @@ function bates(n) {

};
};
}

@@ -62,5 +67,5 @@ function exponential(lambda) {

};
};
}
var version = "0.2.0";
var version = "0.2.1";

@@ -67,0 +72,0 @@ exports.version = version;

@@ -1,1 +0,1 @@

!function(n,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define("d3-random",["exports"],r):r(n.d3_random={})}(this,function(n){"use strict";function r(n,r){var t=arguments.length;return t?1===t?(r=+n,n=0):(n=+n,r=+r-n):(n=0,r=1),function(){return Math.random()*r+n}}function t(n,r){var t=arguments.length;return t?1===t?(n=+n,r=1):(n=+n,r=+r):(n=0,r=1),function(){var t,o,a;do t=2*Math.random()-1,o=2*Math.random()-1,a=t*t+o*o;while(!a||a>1);return n+r*t*Math.sqrt(-2*Math.log(a)/a)}}function o(){var n=t.apply(this,arguments);return function(){return Math.exp(n())}}function a(n){return function(){for(var r=0,t=0;n>t;++t)r+=Math.random();return r}}function e(n){var r=a(n);return function(){return r()/n}}function u(n){return function(){return-Math.log(1-Math.random())/n}}var i="0.2.0";n.version=i,n.randomUniform=r,n.randomNormal=t,n.randomLogNormal=o,n.randomBates=e,n.randomIrwinHall=a,n.randomExponential=u});
!function(n,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r(n.d3_random={})}(this,function(n){"use strict";function r(n,r){return n=null==n?0:+n,r=null==r?1:+r,1===arguments.length?(r=n,n=0):r-=n,function(){return Math.random()*r+n}}function t(n,r){var t,o;return n=null==n?0:+n,r=null==r?1:+r,function(){var e;if(null!=t)e=t,t=null;else do t=2*Math.random()-1,e=2*Math.random()-1,o=t*t+e*e;while(!o||o>1);return n+r*e*Math.sqrt(-2*Math.log(o)/o)}}function o(){var n=t.apply(this,arguments);return function(){return Math.exp(n())}}function e(n){return function(){for(var r=0,t=0;n>t;++t)r+=Math.random();return r}}function u(n){var r=e(n);return function(){return r()/n}}function a(n){return function(){return-Math.log(1-Math.random())/n}}var i="0.2.1";n.version=i,n.randomUniform=r,n.randomNormal=t,n.randomLogNormal=o,n.randomBates=u,n.randomIrwinHall=e,n.randomExponential=a});
{
"name": "d3-random",
"version": "0.2.0",
"version": "0.2.1",
"description": "Generate random numbers from various distributions.",

@@ -23,10 +23,11 @@ "keywords": [

"scripts": {
"pretest": "mkdir -p build && node -e 'process.stdout.write(\"var version = \\\"\" + require(\"./package.json\").version + \"\\\"; export * from \\\"../index\\\"; export {version};\");' > build/bundle.js && rollup -f umd -u d3-random -n d3_random -o build/d3-random.js -- build/bundle.js",
"test": "faucet `find test -name '*-test.js'`",
"prepublish": "npm run test && uglifyjs build/d3-random.js -c -m -o build/d3-random.min.js && rm -f build/d3-random.zip && zip -j build/d3-random.zip -- LICENSE README.md build/d3-random.js build/d3-random.min.js"
"pretest": "mkdir -p build && node -e 'process.stdout.write(\"var version = \\\"\" + require(\"./package.json\").version + \"\\\"; export * from \\\"../index\\\"; export {version};\");' > build/bundle.js && rollup -f umd -n d3_random -o build/d3-random.js -- build/bundle.js",
"test": "faucet `find test -name '*-test.js'` && eslint index.js src",
"prepublish": "npm run test && uglifyjs build/d3-random.js -c -m -o build/d3-random.min.js && rm -f build/d3-random.zip && zip -j build/d3-random.zip -- LICENSE README.md build/d3-random.js build/d3-random.min.js",
"postpublish": "VERSION=`node -e 'console.log(require(\"./package.json\").version)'`; git push && git tag -am \"Release $VERSION.\" v${VERSION} && git push --tags && cp build/d3-random.js ../d3.github.com/d3-random.v0.2.js && cp build/d3-random.min.js ../d3.github.com/d3-random.v0.2.min.js && cd ../d3.github.com && git add d3-random.v0.2.js d3-random.v0.2.min.js && git commit -m \"d3-random ${VERSION}\" && git push"
},
"devDependencies": {
"d3-array": "~0.7.0",
"d3-array": "~0.7.1",
"faucet": "0.0",
"rollup": "0.20.5",
"rollup": "0.25",
"seedrandom": "2",

@@ -33,0 +34,0 @@ "tape": "4",

@@ -10,3 +10,3 @@ # d3-random

```html
<script src="https://d3js.org/d3-random.v0.1.min.js"></script>
<script src="https://d3js.org/d3-random.v0.2.min.js"></script>
```

@@ -18,3 +18,3 @@

<a name="uniform" href="#uniform">#</a> d3.<b>randomUniform</b>([<i>min</i>, ][<i>max</i>])
<a name="randomUniform" href="#randomUniform">#</a> d3.<b>randomUniform</b>([<i>min</i>, ][<i>max</i>])

@@ -30,20 +30,20 @@ Returns a function for generating random numbers with a [uniform distribution](https://en.wikipedia.org/wiki/Uniform_distribution_\(continuous\)). The minimum allowed value of a returned number is *min*, and the maximum is *max*. If *min* is not specified, it defaults to 0; if *max* is not specified, it defaults to 1. For example:

<a name="normal" href="#normal">#</a> d3.<b>randomNormal</b>([<i>mu</i>][, <i>sigma</i>])
<a name="randomNormal" href="#randomNormal">#</a> d3.<b>randomNormal</b>([<i>mu</i>][, <i>sigma</i>])
Returns a function for generating random numbers with a [normal (Gaussian) distribution](https://en.wikipedia.org/wiki/Normal_distribution). The expected value of the generated numbers is *mu*, with the given standard deviation *sigma*. If *mu* is not specified, it defaults to 0; if *sigma* is not specified, it defaults to 1.
<a name="logNormal" href="#logNormal">#</a> d3.<b>randomLogNormal</b>([<i>mu</i>][, <i>sigma</i>])
<a name="randomLogNormal" href="#randomLogNormal">#</a> d3.<b>randomLogNormal</b>([<i>mu</i>][, <i>sigma</i>])
Returns a function for generating random numbers with a [log-normal distribution](https://en.wikipedia.org/wiki/Log-normal_distribution). The expected value of the random variable’s natural logrithm is *mu*, with the given standard deviation *sigma*. If *mu* is not specified, it defaults to 0; if *sigma* is not specified, it defaults to 1.
<a name="bates" href="#bates">#</a> d3.<b>randomBates</b>(<i>n</i>)
<a name="randomBates" href="#randomBates">#</a> d3.<b>randomBates</b>(<i>n</i>)
Returns a function for generating random numbers with a [Bates distribution](https://en.wikipedia.org/wiki/Bates_distribution) with *n* independent variables.
<a name="irwinHall" href="#irwinHall">#</a> d3.<b>randomIrwinHall</b>(<i>n</i>)
<a name="randomIrwinHall" href="#randomIrwinHall">#</a> d3.<b>randomIrwinHall</b>(<i>n</i>)
Returns a function for generating random numbers with an [Irwin–Hall distribution](https://en.wikipedia.org/wiki/Irwin–Hall_distribution) with *n* independent variables.
<a name="exponential" href="#exponential">#</a> d3.<b>randomExponential</b>(<i>lambda</i>)
<a name="randomExponential" href="#randomExponential">#</a> d3.<b>randomExponential</b>(<i>lambda</i>)
Returns a function for generating random numbers with an [exponential distribution](https://en.wikipedia.org/wiki/Exponential_distribution) with the rate *lambda*; equivalent to time between events in a [Poisson process](https://en.wikipedia.org/wiki/Poisson_point_process) with a mean of 1 / *lambda*. For example, exponential(1/40) generates random times between events where, on average, one event occurs every 40 units of time.

@@ -8,2 +8,2 @@ import irwinHall from "./irwinHall";

};
};
}

@@ -5,2 +5,2 @@ export default function(lambda) {

};
};
}

@@ -6,2 +6,2 @@ export default function(n) {

};
};
}

@@ -8,2 +8,2 @@ import normal from "./normal";

};
};
}
export default function(mu, sigma) {
var n = arguments.length;
if (!n) mu = 0, sigma = 1;
else if (n === 1) mu = +mu, sigma = 1;
else mu = +mu, sigma = +sigma;
var x, r;
mu = mu == null ? 0 : +mu;
sigma = sigma == null ? 1 : +sigma;
return function() {
var x, y, r;
do {
var y;
// If available, use the second previously-generated uniform random.
if (x != null) y = x, x = null;
// Otherwise, generate a new x and y.
else do {
x = Math.random() * 2 - 1;

@@ -13,4 +17,5 @@ y = Math.random() * 2 - 1;

} while (!r || r > 1);
return mu + sigma * x * Math.sqrt(-2 * Math.log(r) / r);
return mu + sigma * y * Math.sqrt(-2 * Math.log(r) / r);
};
};
}
export default function(min, max) {
var n = arguments.length;
if (!n) min = 0, max = 1;
else if (n === 1) max = +min, min = 0;
else min = +min, max = +max - min;
min = min == null ? 0 : +min;
max = max == null ? 1 : +max;
if (arguments.length === 1) max = min, min = 0;
else max -= min;
return function() {
return Math.random() * max + min;
};
};
}
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