📦 randts
Random number generator and utilities
Demo in NPM runkit
>With this package, you can create Random Numbers and Timestamp Based Random Numbers with low probability of collision using strong randomized bytes as seeds. You can specify the min and max lengths (which will generate a random length between this values) or configure a specific length.
Installation
With npm:
npm install randts --save
With yarn:
yarn add randts
With pnpm:
pnpm add randts --save
With Git HTTPS:
git clone https://github.com/hebertcisco/randts.git
With Github Cli:
gh repo clone hebertcisco/randts
randts
How to use
To use the package just do as in the script below:
Configuring the random number generation
CJS
const { Configuration } = require('randts');
const randts = require('randts');
const NumberConfig = new Configuration();
NumberConfig.setMinLength(4);
NumberConfig.setMaxLength(randts.NumberLength.getMaxSafeLength());
Generates a random number
const { Generator, Configuration } = require('randts');
const NumberConfig = new Configuration();
const RandomNumber = new Generator(NumberConfig);
console.log('Random Number:');
console.log(RandomNumber.getNumber());
console.log('\n');
console.log('Random Number Value:', RandomNumber.getNumber().getValue());
console.log('\n');
Reconfiguring the random number generation
const randts = require('randts');
const { Configuration } = require('randts');
const NumberConfig = new Configuration();
NumberConfig.reset();
NumberConfig.timestampBased();
NumberConfig.setMinLength(15);
NumberConfig.setMaxLength(randts.NumberLength.getMaxSafeLength());
Generates a random number timestamp based
const randts = require('randts');
const { NumberConfig, Generator } = require('randts');
const RandomNumberTimestampBased = new Generator(NumberConfig);
console.log('Random Number timestamp based:');
console.log(RandomNumberTimestampBased.getNumber());
🤝 Contributing
Contributions, issues and feature requests are welcome!
Feel free to check issues page.
Show your support
Give a
Or buy me a coffee 🙌🏾
📝 License
Copyright © 2022 Hebert F Barros.
This project is MIT licensed.