Random - ES Module for Deno, Node and Web

Usage

import Random from './Random.js';

const r = new Random();
const r = new Random( alea ); // you may pass a random generator function
const r = new Random( Math.random ); // defaults to Math.random

r.int( 0, 10 ); // random integer from 0 to 9
r.real( 0, 3 ); // random real number from 0 to 3 (exclusive)

r.string( 5 );  // random string with length of 5 (eg: ku8rz, 9eirk)
r.string( 5, Random.UPPER_ALPHABETS ); // random string from uppercase alphabets
r.string( 5, Random.UNAMBIGOUS_UPPER_ALPHA_NUMERICS ); // unambigous: No 0, O, 1, I, 3, S..

r.pick( 2, 3, 5, 7, 11 ); // pick one from arguments (eg: 7)
r.pick( [ "a", "e", "i", "o", "u" ]) // you may pass an array

r.weighted( 0.3, 0.7 ) // 0 has 30% chance of getting picked. 1, 70%
r.weighted( 0.2, 0.1, 0.5 )

Issues

For any bug reports or feature requests please post an issue on GitHub.

Author

Vincent
Follow on GitHub Follow on Twitter
Follow on Stack Exchange

License

MIT License (Expat). See LICENSE.md for details.