Skip to content

jzevin/random

Repository files navigation

tiny random

A super lightweight random javaScript library

Travis Build License NPM Version

Demo

StackBlitz Demo

usage (Node.js)

require

import { Random } from 'tiny-random';
var random = new Random();

integers

random.int(); // 0 or 1
random.int(1,100); // 1-100
random.int(-1,1); // -1,0, or -1

real(floats)

random.real(); // 0-1.0
random.real(1.0,10.0); // 1.0-10.0

pick from array

random.pick([1,2,3]); // 1,2, or 3

colors

random.color(); // 'rgb(?,?,?)'
random.color('rgb'); // 'rgb(?,?,?)'
random.color('rgba'); // 'rgba(?,?,?,?)'

random.color('hsl'); // 'hsl(?,?%,?%)'
random.color('hsla'); // 'hsla(?,?%,?%, ?%)'

random.color('hex'); // '#??????'

pick unique or uniq elements from an array

random.unique([1,2,3],2); // [1,2] or [3,1] or [3,2] etc...
random.unique([
  {obj:'foo'},
  {obj:'bar'}
],1); // [{obj:'foo'}] or [{obj:'bar'}]

About

A lightweight random library

Resources

License

Stars

Watchers

Forks

Packages

No packages published