https://github.com/vcgtz/rndjs
Minimal library to generate random values
https://github.com/vcgtz/rndjs
random random-generator
Last synced: over 1 year ago
JSON representation
Minimal library to generate random values
- Host: GitHub
- URL: https://github.com/vcgtz/rndjs
- Owner: vcgtz
- License: mit
- Created: 2022-09-02T01:26:16.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2023-04-21T21:22:43.000Z (about 3 years ago)
- Last Synced: 2025-03-16T20:39:33.599Z (over 1 year ago)
- Topics: random, random-generator
- Language: TypeScript
- Homepage:
- Size: 679 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# rndjs
Minimal library to generate random values. (Now with support for TypeScript!)



## Installation
This module is available through [NPM](https://www.npmjs.com/).
To install this library, you just need to run:
```bash
npm i rndjs
```
Then, you can import it en your project:
```js
const rndjs = require('rndjs');
// or
import * as rndjs from 'rndjs';
```
## Available functions
### `getRandomNumber(): number`
It returns a number between 0 and 1.
```js
rndjs.getRandomNumber();
```
### `getRandomNumberBetween(start: number, end: number): number`
It returns a random number between two numbers, including them.
```js
rndjs.getRandomNumberBetween(10, 25); // It returns a number between 10 and 25
```
### `getRandomBoolean(): boolean`
It returns a random boolean value.
```js
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.
```js
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.
```js
rndjs.getRandomAdjective(); // It returns beautiful for example
```
### `getRandomRGBColor(): RGB`
It returns a random RGB color object. The object has the format `{ r: , g: , b: }`
```js
rndjs.getRandomRGBColor(); // It returns an object like {r: 19, g: 110, b: 166}
```
### `flipACoin(): string`
It simulates flip a coin.
```js
rndjs.flipACoin(); // It returns 'heads' or 'tails'
```
### `rollADice(): number`
It simulates a dice roll.
```js
rndjs.rollADice(); // It returns a number between 1 and 6
```
## License
[MIT](https://github.com/vcgtz/rndjs/blob/main/LICENSE)