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

js-rando

v1.0.9

Published

A library of functions to generate random Ints, Floats, Array Elements, and Color Strings.

Downloads

30

Readme

JS-Rando

JS-Rando provides a class with methods that can be used for easily producing random values including Integers, Floats, Array Elements, Hex Numbers, Hex Colors, RBG Colors & RBGA Colors.

Installation

npm install js-rando

Usage

To use the methods below, import the Rando class and create an instance of it.

import Rando from "js-rando";

let rando = new Rando()

Examples

Working examples of all JS-Rando methods can be viewed at https://js-rando.netlify.app/

Methods

Random decimal.

Random(digits)

  • Returns a random value between 0(inclusive) and 1(exclusive) up to 16 significant digits.
  • The digits argument is optional and specifies the number of signficant digits for the return value. If omitted, the result will default to 16 significant digits.

Random Integer.

RandomInt(min, max)

  • Returns a random integer between the min(inclusive) and max(exclusive)
  • Min & Max arguments must be provided as integers.

Random Float.

RandomFloat(min, max, digits)

  • Returns a random decimal number between the min(inclusive) and max(exclusive).
  • The digits argument is optional and specifies the number of signficant digits for the return value. If omitted, the result will default to 16 significant digits.

Random Array Element.

RandomElement(arr)

  • Returns a random element from an array.
  • The argument arr is required must be an array.'

Random Hex Value.

RandomHex()

  • Returns a random hex value as a 1 chararacter string (0-f)

Random Hex Color.

RandomHexColor()

  • Returns a string of a random hex color

Random RBG Color

RandomRGBColor()

  • Returns a string of a random rbg color with valuees between 0(inclusive) and 256(exclusive).

Random RBGA Color

RandomRGBAColor()

  • Returns a string of a random rbga color with valuees between 0(inclusive) and 256(exclusive) for the RGB values and 0.0 and 1.0 for the alpha value.

Examples

import Rando from "./js-rando";
let rando = new Rando()


rando.Random()
// Returns
// 0.8695750163152240

rando.RandomInt(1,11)
// Returns
// 6

rando.RandomHex()
// Returns
// b

rando.RandomElement(["cat", "dog", "fish"])
// Returns
// "dog"

rando.RandomHexColor()
// Returns
// "#5b927b"

rando.RandomRGBColor()
// Returns
// "rgb(62, 100, 113)"

rando.RandomRGBAColor()
// Returns
// rbga(169, 156, 55, 0.8)

Authors

License

MIT License © Christopher Moriarty