Giter VIP home page Giter VIP logo

random's Introduction

Random

A Tiny Random Utility Generator

License: MIT

Features

  • Alea RNG
  • Seedable
  • Random
    • number
    • between
    • chance
    • itemFromArray
    • entryFromObject
    • keyFromObject
  • Tested with Jest
  • 2kb minified (<1kb minified + gzipped)

Install

git clone https://github.com/RetroVX/random.git

Or download from Zip

Node & Common

const Random = require('./path/to/random.js');

const seed = 'mySeed';
const random = new Random(seed);

Module

import Random from "./path/to/random.mjs";

const seed = 'mySeed';
const random = new Random(seed);

UMD

<script type="text/javascript" src="path/to/random.umd.js"></script>
const seed = 'mySeed';
const random = new window.random(seed);

Examples

// generate a random number between 0 and 1.
// use this in place of Math.random()
random.gen(); -> 0.9401234467513859

// generate a random number with a max number (defaults to 100 if undefined)
random.number(100); -> 42

// generates a random number using a min and max number
random.between(1, 25); -> 17

// percent chance to happen
random.chance(50) -> true

// picks a random item from an array
random.itemFromArray([1, 2, 3, 4, 5]); -> 2

// picks a random key/value pair and outputs as an array
random.entryFromObject({prop1: 'hello', prop2: 'world'}); -> ['prop1', 'hello']

// picks a random key from an object
random.keyFromObject({prop1: 'hello', prop2: 'world'}); -> 'prop2'

// new seed
random.newGenerator(seed);

Credit

Alea

Version 1.3.0

random's People

Contributors

retrovx avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.