0.1.15 • Published 5 years ago

really-random v0.1.15

Weekly downloads
3
License
ISC
Repository
github
Last release
5 years ago

travis badge Coverage Status Maintainability

really-random

Utilities for generating random results. Includes utilities to generate random numbers, integers in range, and randomizing in Arrays.

Installation

const reallyRandom = require('really-random');

Usage

Generate a random number between 0 and 1. This is an alias for Math.random().

const n = reallyRandom.random();

Generate a random Int in range of min to max - 1. randomRange(min, max).

const dieRoll = reallyRandom.randomRange(1, 6);

Generate a random Boolean.

const maybe = reallyRandom.randomBool();

Generate a die roll function. Returns a function that generates die rolls of an n sided die with numbers in the range of 1 to n.

const d6 = dieX(6);
console.log(d6() + d6()); // Outputs 2 to 12

const d20 = dieX(20);
const toHit = d20() + 3;

You can also pass the bonus into the die roll function.

const d6 = dieX(6);
console.log(d6(1)); // Outputs 2 to 7 simulates d6+1

const d20 = dieX(20);
const toHit = d20(3); // Outputs 4 to 23 simulates d20+3

Return a copy of an array with elements randomized.

const cards = ['a', 'b', 'c', 'd'];
const shuffled = reallyRandom.randomArray(cards);

Randomize an array in place.

const cards = ['a', 'b', 'c', 'd'];
const shuffledCards = reallyRandom.shuffleArray(cards);
0.1.15

5 years ago

0.1.14

5 years ago

0.1.13

5 years ago

0.1.12

5 years ago

0.1.11

7 years ago

0.1.10

7 years ago

0.1.9

7 years ago

0.1.8

7 years ago

0.1.7

7 years ago

0.1.6

7 years ago

0.1.5

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago