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

rngee

v0.1.3

Published

An open source JavaScript library for generating random values

Downloads

9

Readme

rngee, an open source JavaScript library for random values

Table of Contents

Features

  • Simple, pure, lightweight functions
  • Get all sorts of random values!
    • Random Numbers
    • Random Colors
    • Random Strings
    • Random Dice Throws (d6, d20 etc)
    • Random Coin Tosses
  • Get single values or multiple values in an array
  • Options to specify:
    • Int, float etc
    • Hexcode, RGB etc
    • Uppercase, Lowercase, numbers, symbols etc
    • Number of dice, number of sides
    • Number of coin tosses
  • _ Work in progress _

Installing

Package Manager

Using npm:

$ npm install rngee

Example

You can import the entire 'rngee' package or the individual functions.

Below is an example of using both methods of calling the functions.

// index.js

import rngee, { coinToss } from 'rngee';

function flipCoinRandomTimes() {
    const numOfTosses = rngee.randomNumber(1,10);
    return coinToss(numOfTosses);
}

console.log(flipCoinRandomTimes()); // An array of "Heads" and/or "Tails"

If you are using require for importing, only default export is available:

const rngee = require('rngee');
console.log(rngee.coinToss()); // "Heads"
console.log(rngee.coinToss(2)); // ["Tails", "Heads"]

All Functions

You can copy and paste the example code below to try it out

  • randomNumbers
import rngee from 'rngee';
/* *
* Generates a random number or an array of random numbers
* @param min: number
* @param max: number
* @param values: number - how many values are generated

* @returns a single random number by default
    If 'values' is greater than 1, then return an array of numbers
*/
console.log(rngee.randomNumbers()); //Returns one values between 1-10
const min = 4;
const max = 20;
console.log(rngee.randomNumbers(min, max)); // Returns one value between 4-20
const values = 4
console.log(rngee.randomNumbers(min, max, values)); // An array of four values between 4 and 20
  • coinToss
import rngee from 'rngee';
/*
* Returns a single coin toss or an array of coin tosses
* @param tosses: number - number of coins to toss (defaults to 1)
* @param win: string - (defaults to "Heads")
* @param loss: string - (defaults to "Tails")

* @returns either "Heads" or "Tails" by default (or specified value)
    If 'tosses' is greater than 1, then return an array of strings
*/
console.log(rngee.coinToss()); // Returns either "Heads" or "Tails"
const tosses = 3;
console.log(rngee.coinToss(3)); // Returns an array of "Heads" or "Tails"
const win = "USC";
const loss = "UCLA";
console.log(rngee.coinToss(1, win, loss)); // Returns either "USC" or "UCLA"
  • randomColor
import rngee from 'rngee';
/*
* Returns a random Hexcode of RGB value
* @param format: string - only valid options are 'hex' or 'rgb' ('hex' is the default format)

* @returns a random Hexcode like #FFFFFF by default
    If 'rgb' will return a RGB value like rgb(0,0,0)
*/
console.log(rngee.randomColor()); // Returns a random Hexcode value
console.log(rngee.randomColor('hex')); // Returns a random Hexcode value
console.log(rngee.randomColor('rgb')); // Returns a random RGB value
  • diceRoll
import rngee from 'rngee';
/*
* Returns the results of dice rolls
* @param tosses: number - specify the number of dice to toss (defaults to 1)
* @param sides: number - specify the number of sides, ex. 4, 6, 10, 20 (defaults to 6)

* @returns one number between 1-6 by default
    If 'tosses' is greater than 1, then return an array of numbers
*/
console.log(rngee.diceRoll()); // Returns a single dice roll value between 1-6
const tosses = 3;
console.log(rngee.diceRoll(tosses)); // Returns 3 dice rolls between 1-6 in an array
const sides = 20;
console.log(rngee.diceRoll(1, sides)); // Returns 1 dice roll between 1-20 (d20)
  • randomString
import rngee from 'rngee';
/*
* Generates a random string
* @param length: number - specify the length of the random string (defaults to 8)
* @param lower: boolean - to include lower case characters (defaults to true)
* @param upper: boolean - to include upper case characters (defaults to true)
* @param nums: boolean - to include number characters (defaults to true)
* @param symbols: boolean - to include symbol characters (defaults to true)

* @returns a random length string
*/
console.log(rngee.randomString()); // Returns a random string of 8 characters
const length = 12
const lower = true;
const upper = false;
const nums = true;
const symbols = false;
console.log(rngee.randomString(12, lower, upper, nums, symbol)); // Returns a string of 12 characters, only lowercase letters and numbers