rndjs
TypeScript icon, indicating that this package has built-in type declarations

2.0.2 • Public • Published

rndjs

Minimal library to generate random values. (Now with support for TypeScript!)

npm npm github actions

Installation

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';

Available functions

getRandomNumber(): number

It returns a number between 0 and 1.

rndjs.getRandomNumber();

getRandomNumberBetween(start: number, end: number): number

It returns a random number between two numbers, including them.

rndjs.getRandomNumberBetween(10, 25); // It returns a number between 10 and 25

getRandomBoolean(): boolean

It returns a random boolean value.

rndjs.getRandomBoolean(); // It returns true or false

getRandomChar(options?: RandomCharOptions): string

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

getRandomAdjective(): string

It returns a random adjective.

rndjs.getRandomAdjective(); // It returns beautiful for example

getRandomRGBColor(): RGB

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}

flipACoin(): string

It simulates flip a coin.

rndjs.flipACoin(); // It returns 'heads' or 'tails'

rollADice(): number

It simulates a dice roll.

rndjs.rollADice(); // It returns a number between 1 and 6

License

MIT

Package Sidebar

Install

npm i rndjs

Weekly Downloads

30

Version

2.0.2

License

MIT

Unpacked Size

53.6 kB

Total Files

32

Last publish

Collaborators

  • vcgtz