Minimal library to generate random values. (Now with support for TypeScript!)
This module is available through NPM.
To install this library, you just need to run:
npm i rndjs
Then, you can import it en your project:
const rndjs = require('rndjs');
// or
import * as rndjs from 'rndjs';
It returns a number between 0 and 1.
rndjs.getRandomNumber();
It returns a random number between two numbers, including them.
rndjs.getRandomNumberBetween(10, 25); // It returns a number between 10 and 25
It returns a random boolean value.
rndjs.getRandomBoolean(); // It returns true or false
It returns a random character between a
and z
. If you pass an object with the attribute upper: true
, this method returns the uppercase character.
rndjs.getRandomChar(); // It returns a char between a-z
rndjs.getRandomChar({ upper: true }); // It returns a char between A-Z
It returns a random adjective.
rndjs.getRandomAdjective(); // It returns beautiful for example
It returns a random RGB color object. The object has the format { r: <number>, g: <number>, b: <number> }
rndjs.getRandomRGBColor(); // It returns an object like {r: 19, g: 110, b: 166}
It simulates flip a coin.
rndjs.flipACoin(); // It returns 'heads' or 'tails'
It simulates a dice roll.
rndjs.rollADice(); // It returns a number between 1 and 6