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

@nastyox/rando.js

v2.0.6

Published

The world's easiest, most powerful random function.

Downloads

3,053

Readme

Rando.js, Version: 2.0.6

Rando.js: The world's easiest, most powerful random function.

What's all the hullabaloo?

Rando.js helps JavaScript developers code randomness more simply, readably, and securely. Whether you need to find a random int/float between two numbers, pick a random value from an array, choose a random element from your jQuery object, grab a character from a string, toss a coin, or do anything of the like while even preventing repetitions, we've got you covered at a cryptographically strong level. The best part? Our library is extremely lightweight and developer friendly- which means it won't take a toll on your project, and it's uber-simple to implement.

Usage

//Install:
npm i @nastyox/rando.js
    
//Then, paste this in your JavaScript file:
const {rando, randoSequence} = require('@nastyox/rando.js');

//Note: If your project is a module, you can paste this in your JavaScript file instead:
import {rando, randoSequence} from '@nastyox/rando.js';

Examples

rando()                       //a floating-point number between 0 and 1 (could be exactly 0, but never exactly 1)  
rando(5)                      //an integer between 0 and 5 (could be 0 or 5)  
rando(5, 10)                  //a random integer between 5 and 10 (could be 5 or 10)  
rando(5, "float")             //a floating-point number between 0 and 5 (could be exactly 0, but never exactly 5)  
rando(5, 10, "float")         //a floating-point number between 5 and 10 (could be exactly 5, but never exactly 10)  
rando(true, false)            //either true or false  
rando(["a", "b"])             //{index:..., value:...} object representing a value of the provided array OR false if array is empty  
rando({a: 1, b: 2})           //{key:..., value:...} object representing a property of the provided object OR false if object has no properties  
rando($("div"))               //{index:..., value:...} object representing a jQuery element from the provided jQuery element set OR false if the provided jQuery element set does not contain any elements.  
rando("Gee willikers!")       //a character from the provided string OR false if the string is empty. Reoccurring characters will naturally form a more likely return value  
rando(null)                   //ANY invalid arguments return false

--> Prevent repetitions by grabbing a sequence and looping through it

randoSequence(5)              //an array of integers from 0 through 5 in random order  
randoSequence(5, 10)          //an array of integers from 5 through 10 in random order  
randoSequence(["a", "b"])     //an array of {index:..., value:...} objects representing the values of the provided array in random order  
randoSequence({a: 1, b: 2})   //an array of {key:..., value:...} objects representing the properties of the provided object in random order  
randoSequence($("div"))       //an array of {index:..., value:...} objects representing all jQuery elements from the provided jQuery element set in random order.  
randoSequence("Good gravy!")  //an array of the characters of the provided string in random order  
randoSequence(null)           //ANY invalid arguments return false