npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

rands

v1.0.0

Published

A JavaScript library for generating pseudorandom numbers

Readme

Rands.js

Rands.js provides methods to generate pseudorandom numbers from various distributions (e.g., uniform, Gaussian, Poisson, binomial, etc.). Rands.js can be used in conjunction with a seeded random number generator (RNG) to produce repeatable sequences of random values.

Installation

With NPM

npm install rands

In your code:

var Rands = require('rands');
var r = new Rands();

Directly in the browser

While a tool like Webpack or Browserify is recommended for use in the browser, the rands.min.js script is also provided, which exposes the window.Rands global variable:

<script src="path/to/rands.min.js"></script>
<script>
  var r = new Rands();
  ...
</script>

Random distributions

The library provides methods to generate values from the following distributions.

In each case, the final argument length is optional. When included, the function returns an array of random variables of length length. When omitted, the function returns a single numeric value.

Bernoulli

Generate Bernoulli random variable(s) with parameter p:

r.bernoulli(p, [length])

Binomial

Generate binomial random variable(s) given n trials and p probability of success in each trial:

r.binomial(n, p, [length])

Exponential

Generate exponential random variable(s) with rate parameter lambda:

r.exponential(lambda, [length])

Integer

Generate uniformly distributed integer(s) in range [min, max):

r.integer(min, max, [length])

Normal / Gaussian

Generate normally distributed random variable(s) with mean mean and standard deviation stdev, where mean=0 and stdev=1 by default:

r.normal([mean], [stdev], [length])

Poisson

Generate Poisson random variable(s) with parameter lambda:

r.poisson(lambda, [length])

Rayleigh

Generate Rayleigh random variable(s) with scale parameter sigma:

r.rayleigh(sigma, [length])

Uniform

Generate uniform random variable(s) in range [min, max), where min=0 and max=1 by default:

r.uniform([min], [max], [length])

Utility functions

A few static methods are provided:

Mean

Compute the mean of the numbers contained in in array a:

Rands.mean(a)

Variance

Compute the variance of the numbers contained in array a:

Rands.variance(a)

Generating a repeatable sequence of random variables using a seeded random number generator function

The Rands([rngFunc]) constructor accepts a uniform random number generator function as an optional argument. By providing a seeded RNG function, your code can generate the same sequence of pseudorandom numbers every time it runs.

This is demonstrated in following example using David Bau's seedrandom.js package. The script will print the same number to the console every time it runs:

var Rands = require('rands');
var seedrandom = require('seedrandom');

var rngFunc = seedrandom('charlotte');
var r = new Rands(rngFunc);

console.log(r.uniform());

When an RNG function is not passed to the Rands constructor, the library will fall back to the built-in Math.random() function.