Skip to content

generates random numbers between two integers (both inclusive) without repetition

Notifications You must be signed in to change notification settings

manastunga787/xrand

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This is a simple tiny library to generate numbers between two integers (both inclusive) randomly without repetition.

    npm install --save xrand
const Xrand = require("xrand");

// supply two numbers to generate unique random numbers

const xrand = new Xrand(1, 3);

To generate random number call xrand.generate() method

// to generate a number random number;

console.log(xrand.generate());

console.log(xrand.generate());

console.log(xrand.generate());

after 3 random numbers between 1 to 3 further call to generate returns false

console.log(xrand.generate());

// returns false
const myRand = new Xrand(1, 100);

for (let i = 1; i <= 100; i++) {

    // this will print 100 numbers between 1 to 100 
    // (both inclusive) randomly without repetition
    
    console.log(myRand.generate());
}

// further call to myRand.generate() return false

console.log(myRand.generate());

To get all numbers between two integers randomly at once use xrand.generateAll()

 const values = new Xrand(-5, 5).generateAll();

About

generates random numbers between two integers (both inclusive) without repetition

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published