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-all

v1.1.0

Published

Generates random numbers, unique random numbers.

Downloads

80

Readme

random-all

Generates random numbers, unique random numbers

  const random = require('random-all')
  
  let uniqueValue = random.getUnique(1,10);
  let randomInt = random.getInt(1,10);
  let randomFloat = random.getFloat(1,10);

Installation

This is a Node.js module available through the npm registry. Installation is done using the npm install command:

  npm install --save random-all

Usage

  const random = require('random-all')
  • getUnique(min,max) : Returns a unique random number from (including) min to (including) max.
    After all unique value between min and max it will restart cycle.

    **IMPORTANT - getUnique(min,max) will reset when min and max is changed. To avoid reset use random.new() to get a new object. **

    • min : minimum value of random number. Defaults to 1.

    • max : maximum value of random number. Defaults to 100.

        const random = require('random-all')
      
        let val = random.getUnique(1,10);// unique val is between 1 and 10.
        let val = random.getUnique()// unique val is between 1 and 100.
             
        **IMPORTANT - RESET EXAMPLE**
              
          //file1.js
          let firstInterval = setInteval(1000,function(){
            //This resets(You may get same value) whenever min or max changed in secondInterval.
            let val = random.getUnique(1,10);
            console.log(val)
          });
               
          let secondInterval = setInteval(1000,function(){
            //This resets(You may get same value) because min and max is changed in firstInterval.
            let val = random.getUnique(20,30);
            console.log(val);
          });
  • getInt(min,max) : Returns a random number from (including) min to (including) max.

    • min : minimum value of random number. Defaults to 1.

    • max : maximum value of random number. Defaults to 100.

        const random = require('random-all')
      
        let val = random.getInt(1,10);// val is between 1 and 10.
        let val = random.getInt()// val is between 1 and 100.
      
  • getFloat(min,max) : Returns a random number from (including) min to (including) max.

    • min : minimum value of random number. Defaults to 1.

    • max : maximum value of random number. Defaults to 100.

        const random = require('random-all')
      
        let val = random.getFloat(1,10);// val is between 1 and 11.
        let val = random.getFloat(0,0);// val is between 0 and 1.
        let val = random.getFloat(1,1);// val is between 1 and 2.
        let val = random.getFloat()// val is between 1 and 101.
      
  • getChar(str,isUnique) : Returns a random char from string given.

    • str : string value from which a random char to be fetched. Defaults to "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".

    • isUnique : Return unique char.

        const random = require('random-all')
      
        let val = random.getChar();// val will be a char from "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
        let val = random.getChar("abc");// val will be a or b or c.
      
        //Calling in a loop without unique
        for(let i = 0;i<4;i++){
          console.log(random.getChar("abc"));
        } //output can be a,b,a,a;
      
        //Calling in a loop with unique
        for(let i = 0;i<4;i++){
          console.log(random.getChar("abc",true));
        } //output can be b,a,c,a;
      
  • getBoolean(percent) : Returns a random boolean value.

    • percent : this percent of times true will be returned. Defaults to 50

        const random = require('random-all')
      
        let val = random.getBoolean(); Probabilty of true and false is 50
        let val = random.getBoolean(30); Probabilty of true and false is 30 and 70 repectively.
      
  • choices(population,weights) : Return a random element from the non-empty sequence according to there weight.

    IMPORTANT - use new() to avoid confusions

    • population : elements from which an element should be choosen.

    • weights : weights of each element, the sum should be equal to 100.

        const random = require('random-all')
      
        let val = random.choices(["a","b","c"],[10,40,60]);// val will be a or b or c, occurence would be based on there weights
  • setChoices(population,weights) : Used to set the elements and there weigts, later used by choices(). This is recommeded over passing parameters directly to choices()

    IMPORTANT - use new() to avoid confusions

    • population : elements from which an element should be choosen.

    • weights : weights of each element, the sum should be equal to 100.

        const random = require('random-all')
        random.setChoices(["a","b","c"],[10,40,60]);
        let val = random.choices();// val will be a or b or c, occurence would be based on there weights.

Advanced

  • new(min,max) : Returns a new object.

    **IMPORTANT - This can be used to avoid reset problem of getUnique fumction. **

      const random = require('random-all')
    
      let obj1 = random.new();
      let obj2 = random.new();
         
      obj1.getUnique(1,10);
      obj1.getInt(1,10);
      obj1.getChar();
         
      obj2.getUnique(1,10);
      obj2.getInt(1,10);
      obj2.getChar();
         
      **IMPORTANT - RESET EXAMPLE**
          
        //file1.js
        let firstInterval = setInteval(1000,function(){
          //This resets(You may get same value) whenever min or max changed in secondInterval.
          let obj = random.new();
          let val = obj1.getUnique(1,10);
          console.log(val)
        });
           
        let secondInterval = setInteval(1000,function(){
          //This resets(You may get same value) because min and max is changed in firstInterval.
          let obj = random.new();
          let val = obj.getUnique(20,30);
          console.log(val);
        });