1.0.4 • Published 3 years ago

@ts-pro/unique-random-number v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Unique Random Number

Fast & simple unique random numbers generator

This lib can generate unique numbers for big ranges. It's very simple in usage, just check it out.

Installation

npm:

npm install @ts-pro/unique-random-number

yarn:

yarn add @ts-pro/unique-random-number

Usage

Simple example of usage.

import { UniqueRandomNumber } from 'unique-random-number';
const unique = new UniqueRandomNumber(0, 1000000);

console.log(unique.get()); // Will print unique random number in 0 ... 1000000 ( inclusive )

What will happen if random numbers reach the end ?

import { UniqueRandomNumber } from 'unique-random-number';
const unique = new UniqueRandomNumber(0, 2);

console.log(unique.get()); // Will print 0 or 1 or 2
console.log(unique.get()); // Will print 0 or 1 or 2
console.log(unique.get()); // Will print 0 or 1 or 2
console.log(unique.get()); // Will print undefined which means that we have riched the end

You can work with iterators ( this loop will end when it riches last number, you don't have to write any conditions ):

import { UniqueRandomNumber } from 'unique-random-number';
const unique = new UniqueRandomNumber(0, 100);

for(let n of unique) {
  console.log(n); // Will print numbers between 0 ... 100
}

You can use random number inside strings ( from v1.0.4 ):

import { UniqueRandomNumber } from 'unique-random-number';
const unique = new UniqueRandomNumber();

console.log(`Unique random number: ${unique}`); // Will print specified string with unique random number inside

License

Unique random number is MIT-licensed open-source software by Oleksandr Havrashenko.

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago