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 🙏

© 2024 – Pkg Stats / Ryan Hefner

rndom

v1.2.0

Published

A microlibrary for common tasks that involve randomness

Downloads

8

Readme

rndom

A microlibrary for generating random data. I mostly use this for unit testing. Not to be used for security purposes as it just uses the base JS random implementations

Use

Install

npm install rndom

Import

    let rndom = require("rndom"); //old
    
    import rndom from "rndom"; //ES6

Generate values

    // create a random value between 10 and 20
    let myRandomNumber = rndom.between(10, 20);

Available Functions

The functions available are as follows, detailed descriptions are provided below.

  • between
  • intBetween
  • oneOf
  • nOf
  • color
  • coinflip
  • weightedCoinflip

Float Interval

let min = 10;
let max = 20;
rndom.between(min, max);

Description: Generates a random float between min and max

Params:

  • min: the lower-bound for the return value (inclusive)
  • max: the upper-bound for the return value (non-inclusive)

Returns: A Floating-point value in the range [min, max)

Integer Interval

let min = 10;
let max = 20;
rndom.intBetween(min, max);

Description: Generates a random integer between min and max

Params:

  • min: the lower-bound for the return value (inclusive)
  • max: the upper-bound for the return value (non-inclusive)

Returns: An integer value in the range [min, max)

oneOf

let a = [1,2,3];
rndom.oneOf(a);

Description: Selects a random element of an array

Params:

  • a: the array to select from

Aliases: Adds an alias to the returned element

Returns: A random element that is part of a

nOf

let a = [1,2,3];
let n = 2;
rndom.nOf(n, a);

Description: Generates a random n-length sub-array of the provided array

Params:

  • n: length of the output sub-array, requires n <= a.length
  • a: the array to choose elements from

Aliases: Adds an alias to each returned element in the output array

Returns: An array of length n where each element is in the input array a

Color String

rndom.color();

Description: Generates a random web color

Params:

  • [scheme]: optional parameter, must be "hex", "rgb", or "named"

Returns: A string representing a web color corresponding to the scheme (e.g. hex: "#ffffff" rgb: "rbg(255,255,255)" named: "AntiqueWhite"). If no scheme is provided, the default is hex.

Coin Flip

rndom.coinflip();

Description: Performs a fair coinflip

Returns: A boolean corresponding to success or failure

Weighted Coin Flip

let p = 0.75;
rndom.weightedCoinflip(p);

Description: Performs a weighted coinflip

Params:

  • p: the probability the coinflip will be successful. Must be in the range [0,1]

Returns: A boolean corresponding to success or failure