easy-random

An easy generator of random bool, int, or double values.

Usage no npm install needed!

<script type="module">
  import easyRandom from 'https://cdn.skypack.dev/easy-random';
</script>

README

easy-random.js

Build Status

An easy to use random helper for your applications.

Install

You can get it on npm.

npm install easy-random --save

Setup

First, you need to instantiate it using Node.js module loading system.

const random = require('easy-random');

Or ES6 module, too.

import random from 'easy-random';

Usage

nextBool

You can generate random booleans:

random.nextBool(); // true or false

nextInt

Generate random int numbers:

random.nextInt(10); // Between 0 and 9

nextDouble

Generate random double numbers:

random.nextDouble(); // Between 0.0 and 1.0: [0, 1)

choice

Choose a random element:

random.choice('abcdefghij'); // choose a random char on a String
random.choice('[1, 2, 3, 4, 5, 6]'); // choose a random item on a Array

shuffle

Shuffle the sequence in place:

const items = [1, 2, 3, 4, 5, 6, 7];
random.shuffle(items); // [7, 3, 2, 5, 6, 4, 1]

sample

Return a x length list of unique elements chosen from the population sequence.

random.sample([1, 2, 3, 4, 5],  3); // Choose 3 elements. [4, 1, 5]

License

MIT License © Cesar William