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

random-nodejs

v1.0.9

Published

A simple and flexible npm library that creates various type of Random Numbers.

Downloads

3

Readme

Node.js Random Numbers and String

A simple and flexible npm library that creates various type of Random Numbers and String. Works in both NodeJS and the browser.

Installation

npm i random-nodejs --save

Import

var rand = require("random-nodejs");

Numbers API

String API

random

Return, Random float numbers.

rand.random(baseNum, fixedNum);

baseNum represent base of the number system. Default is 1 Specified baseNum as 1, 10, 100, 1000 ... fixedNum represent max length of output float number.

rand.random(1, 5)     // Ex. output 0.41008,  0.89666

rand.random(10, 5)    // Ex. output 6.30851,  5.64046

rand.random(100, 5)   // Ex. output 44.75786, 30.95153

rand.random(1000, 3)  // Ex. output 422.649,   437.101

bool

Return, Random true or false values.

rand.bool(thresholdNum);

Specified thresholdNum between 0 and 1 Default is 0.5 When thresholdNum = 0.5, Get true => 50%, false => 50% When thresholdNum = 0.3, Get true => 30%, false => 70%

rand.bool(0.8)  // Ex. output true, true, true, false

rand.bool(0.2)  // Ex. output true, false, false, false

intnum

Return, Random integer numbers between min and max values.

rand.intnum(min, max);

Default min = 0 Default max = 1

rand.intnum(-5, 10)    // Ex. output 2 , 0, 3, -5

rand.intnum(-15, -5)   // Ex. output -4 , -10, -8, -5

floatnum

Return, Random float numbers between min and max values.

rand.floatnum(min, max, fixedNum);

Specified fixedNum to get max length of output float number. Default min = 0 Default max = 1

rand.floatnum(-5, 10, 5)   // Ex. output -4.92252, 9.29047, 9.30004, -2.33519

rand.floatnum(-5, 10, 2)   // Ex. output 1.56, -3.43 7.33

option

Return, Random numbers inside the user-defined array of numbers.

const arr = ([1, 2, 3, 4]);

random.option(arr);           // Ex. output 3, 1, 4, 1, 2

multiples

Return, Random numbers in multiples of a number(mutiples of mul value) in between min and max values.

rand.multiples(min, max, mul);

Default mul = 0.1 Default min = 0 Default max = 1

rand.multiples(-10, 10, 2)     // Ex. output -4, 6, -8, 10

rand.multiples(-10, 10, 0.2)   // Ex. output  10, -1.4, -2.8, 6.4

capital

Return, Capital letters.

rand.capital();

Ex. Output  A, Z, E, C ...

simple

Return, Simple letters.

rand.simple();

Ex. Output  g, j, l, o ...

words

Return, Random Words inside the user-defined array of words.

var things = ['Rock', 'Paper', 'Scissor'];
rand.words(things);

Ex. Output  Paper, Scissor, Rock, Rock ...

Contributing

You can contribute to this project. You just need to create a pull request which will be revised, merged to main branch (if the code doesn't break the project) and published as a new release.