Skip to content

Get an integer between a min and max, bring your own random number generator.

License

Notifications You must be signed in to change notification settings

vweevers/uniform-integer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

uniform-integer

Get an integer between a min and max, bring your own random number generator.
See also zipfian-integer.

npm status node Travis build status JavaScript Style Guide

Usage

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:

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.

num = sample()

Get a random integer between min (inclusive) and max (inclusive).

Install

With npm do:

npm install uniform-integer

License

MIT © 2019-present Vincent Weevers

About

Get an integer between a min and max, bring your own random number generator.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published