Home Manual Reference Source

Overview

Installation

Can be managed using jspm or npm.

jspm

jspm install npm:@randomized/random

npm

npm install @randomized/random --save

Usage

:warning: Depending on your environment, the code may require regeneratorRuntime to be defined, for instance by importing regenerator-runtime/runtime.

await import( 'regenerator-runtime/runtime.js' ) ;
// or
import 'regenerator-runtime/runtime.js' ;

Then

const { ... } = await import( '@randomized/random' ) ;
// or
import { ... } from '@randomized/random' ;

Examples

import { randint , randfloat , sample , shuffle } from '@randomized/random' ;

randfloat( 0 , 1 ) ; // 0.19876947347074747
randfloat( 0 , 1 ) ; // 0.23755912738852203

randint( 0 , 100 ) ; // 57
randint( 0 , 100 ) ; // 31

let a = [ 0 , 1 , 2 , 3 ] ;

sample( 1 , a , 0 , 4 ) ;
a ; // [ 0 , 1 , 2 , 3 ]

sample( 1 , a , 0 , 4 ) ;
a ; // [ 1 , 0 , 2 , 3 ]

shuffle( a , 0 , 4 ) ;
a ; // [ 1 , 3 , 0 , 2 ]

shuffle( a , 0 , 4 ) ;
a ; // [ 3 , 2 , 1 , 0 ]