diff --git a/README.md b/README.md index 957f78b..6c1bc93 100644 --- a/README.md +++ b/README.md @@ -4,43 +4,43 @@ Generate random numbers from various distributions. ## Installing -If you use NPM, `npm install d3-random`. Otherwise, download the [latest release](https://github.com/d3/d3-random/releases/latest). +If you use NPM, `npm install d3-random`. Otherwise, download the [latest release](https://github.com/d3/d3-random/releases/latest). The released bundle supports AMD, CommonJS, and vanilla environments. Create a custom build using [Rollup](https://github.com/rollup/rollup) or your preferred bundler. You can also load directly from [d3js.org](https://d3js.org): + +```html + +``` + +In a vanilla environment, a `d3_random` global is exported. [Try d3-random in your browser.](https://tonicdev.com/npm/d3-random) ## API Reference -# uniform([min, ][max]) +# d3_random.uniform([min, ][max]) 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: ```js -uniform(6)(); // Returns a number greater than or equal to 0 and less than 6. -uniform(1, 5)(); // Returns a number greater than or equal to 1 and less than 5. +d3_random.uniform(6)(); // Returns a number greater than or equal to 0 and less than 6. +d3_random.uniform(1, 5)(); // Returns a number greater than or equal to 1 and less than 5. ``` Note that you can also use the built-in [Math.random](https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Math/random) to generate uniform distributions directly. For example, to generate a random integer between 0 and 99 (inclusive), you can say `Math.random() * 100 | 0`. -# normal([mu][, sigma]) +# d3_random.normal([mu][, sigma]) 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. -# logNormal([mu][, sigma]) +# d3_random.logNormal([mu][, sigma]) 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. -# bates(n) +# d3_random.bates(n) Returns a function for generating random numbers with a [Bates distribution](https://en.wikipedia.org/wiki/Bates_distribution) with *n* independent variables. -# irwinHall(n) +# d3_random.irwinHall(n) Returns a function for generating random numbers with an [Irwin–Hall distribution](https://en.wikipedia.org/wiki/Irwin–Hall_distribution) with *n* independent variables. -# exponential(lambda) +# d3_random.exponential(lambda) 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. - -## Changes from D3 3.x: - -* Added a [uniform](#uniform) random number generator. - -* Added an [exponential](#exponential) random number generator. diff --git a/package.json b/package.json index 97adbec..31951d4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "d3-random", - "version": "0.1.0", + "version": "0.1.1", "description": "Generate random numbers from various distributions.", "keywords": [ "d3", @@ -25,7 +25,7 @@ "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" }, "devDependencies": { - "d3-arrays": "~0.3.1", + "d3-array": "~0.6.1", "faucet": "0.0", "rollup": "0.20.5", "seedrandom": "2",