New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

random-utils-and-tools

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

random-utils-and-tools

Random tools

latest
npmnpm
Version
1.0.8
Version published
Maintainers
1
Created
Source

Installation

npm i random-utils-and-tools

Get started

let random = new (require('random-utils-and-tools').Random)()

Usage

// Constants  
let digits          = random.digits; // Digits 0-9  
let specials        = random.specials; // Special characters  
let ascii_lowercase = random.ascii_lowercase; // Lowercase alphabet  
let ascii_uppercase = random.ascii_uppercase; // Uppercase alphabet  
let ascii_letters   = random.ascii_letters // Both lowercase and uppercase letters  
  

// Range
random.range(1, 100) 
// [1, 2, 3, ..., 99]

random.range(100) // return all integers between 0-99 
// [0, 1, 2, 3, ..., 99]

random.range(1, 100, 2) // returns all odd numbers between 1-100
// [1, 3, 5, 7, ..., 97, 99]

random.range(100, 1, -1) // return range 2-100 reversed
// [100, 99, 98, ..., 3, 2]

random.range(100, 1, -5)
// [100, 95, 90, ..., 10, 5]


  

// Random integer  
random.int(1, 10) // Random integer in range 1-10  
random.int(5) // Random integer in range 0-5  
  
  
// Random float  
random.float(1, 2) // Random float in range 1-2  
random.float(5) // Random float in range 0-5  
random.float() // Random float in range 0-1  
  
  
// Random boolean  
random.boolean() // true or false  
  
  
// Others  
random.randomAsciiLetters(length = 10) // Random 10 ascii letters as string  
random.randomSpecials(length = 10) // Random 10 special characters as string  
random.randomDigits(length = 10) // Random 10 digits as string  
random.randomAsciiLowercase(length = 10) // Random 10 lowercase ascii letters as string  
random.randomAsciiUppercase(length = 10) // Random 10 uppercase ascii letters as string  
  
  
  
// Random element from collection (string, array, etc.)  
random.choice([99, 42, 58, 19, 52]);  
random.choice("Hello, world");  
  
// Also can take few arguments  
random.choice(  
    [1, 2, 3, 4, 5],  
  "Hello, world"  
) // Chooses between each elements of all arguments  
  
  
  
// Few random elements from collection (Elements can repeat)  
random.chooseFew(  
    arr = [42, 94, 29, 10, 40], // Array  
  count = 3 // Choices count  
)  
  
// Few random elements without repeating elements  
random.chooseFew(  
    arr = [92, 58, 29, 104, 285, 10], // Array  
  count = 3, // Choice count,  
  repeat = false // Default is true so there can be repeating elements  
)  
// If repeat is false then count should be lesser or equal to arr.length  
  
  
  
// Random count of random elements from collection with no repeating items
random.chooseAny(  
    arr = [49, 4290, 63, 99, 29],  
  repeat = false,  
  limit = 2  
)  
// Limit is the maximum possible length of list the method returns  
// If repeat is true (default value), then limit can be any integer  
// If repeat is false, then limit must be between 0, arr.length



// Randomly shuffle list
random.shuffle(
    [1, 2, 3, 4, 5]
)

// Also takes few parameters and returns one list with all parameters together
random.shuffle(
    [1, 2, 3, 4, 5],
    "Hello, world",
[6, 7, 8, 9, 10]
)



// Get randomly shuffled list of numbers in range
random.randomRange(1, 100) // Is equal to random.shuffle(random.range(1, 100))
random.randomRange(100, 1, -1) // = random.shuffle(random.range(100, 1, -1))
random.randomRange(1000) // = random.shuffle(random.range(1000))

Keywords

random

FAQs

Package last updated on 03 Dec 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts