https://github.com/vweevers/uniform-integer
Get an integer between a min and max, bring your own random number generator.
https://github.com/vweevers/uniform-integer
nodejs number-generator random uniform-distribution
Last synced: about 1 month ago
JSON representation
Get an integer between a min and max, bring your own random number generator.
- Host: GitHub
- URL: https://github.com/vweevers/uniform-integer
- Owner: vweevers
- License: mit
- Created: 2019-06-01T17:30:39.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-05-25T04:08:42.000Z (almost 5 years ago)
- Last Synced: 2025-03-28T21:39:08.036Z (about 1 month ago)
- Topics: nodejs, number-generator, random, uniform-distribution
- Language: JavaScript
- Size: 9.77 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# uniform-integer
> **Get an integer between a min and max, bring your own random number generator.**
> See also [`zipfian-integer`](https://github.com/vweevers/zipfian-integer).[](https://www.npmjs.org/package/uniform-integer)
[](https://www.npmjs.org/package/uniform-integer)
[](http://travis-ci.org/vweevers/uniform-integer)
[](https://standardjs.com)## Usage
```js
const uniform = require('uniform-integer')
const sample = uniform(1, 100)console.log(sample())
console.log(sample())
```This logs two random integers between 1 and 100 (inclusive). You can optionally inject a (seeded) random number generator. The following example always returns the same integers in sequence unless you change the seed:
```js
const random = require('pseudo-math-random')('a seed')
const sample = uniform(1, 100, random)
```## API
### `sample = uniform(min, max[, rng])`
Create a new random number generator with a uniform distribution. The `rng` if provided must be a function that returns a random floating-point number between 0 (inclusive) and 1 (exclusive). It defaults to [`Math.random`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random).
### `num = sample()`
Get a random integer between `min` (inclusive) and `max` (inclusive).
## Install
With [npm](https://npmjs.org) do:
```
npm install uniform-integer
```## License
[MIT](LICENSE.md) © 2019-present Vincent Weevers