Skip to content

Commit

Permalink
Update README.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Dec 18, 2015
1 parent ba98775 commit c74f2e2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<script src="https://d3js.org/d3-random.v0.1.min.js"></script>
```

In a vanilla environment, a `d3_random` global is exported. [Try d3-random in your browser.](https://tonicdev.com/npm/d3-random)

## API Reference

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

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`.

<a name="normal" href="#normal">#</a> <b>normal</b>([<i>mu</i>][, <i>sigma</i>])
<a name="normal" href="#normal">#</a> d3_random.<b>normal</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> <b>logNormal</b>([<i>mu</i>][, <i>sigma</i>])
<a name="logNormal" href="#logNormal">#</a> d3_random.<b>logNormal</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> <b>bates</b>(<i>n</i>)
<a name="bates" href="#bates">#</a> d3_random.<b>bates</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> <b>irwinHall</b>(<i>n</i>)
<a name="irwinHall" href="#irwinHall">#</a> d3_random.<b>irwinHall</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> <b>exponential</b>(<i>lambda</i>)
<a name="exponential" href="#exponential">#</a> d3_random.<b>exponential</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.

## Changes from D3 3.x:

* Added a [uniform](#uniform) random number generator.

* Added an [exponential](#exponential) random number generator.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "d3-random",
"version": "0.1.0",
"version": "0.1.1",
"description": "Generate random numbers from various distributions.",
"keywords": [
"d3",
Expand All @@ -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",
Expand Down

0 comments on commit c74f2e2

Please sign in to comment.