mk-randoms
v1.2.3
Published
Random integer, Random array element, Random string, Random boolean with given probability, Random offset of numerical
Downloads
7
Maintainers
Readme
mk-randoms
Generate random values of different types with clear syntax with 1K lib.
Random integer, random array element, random string, random boolean with given probability, random offset of numerical.
Type declaration added for Typescript.
Installation
npm install --save mk-randoms
Inclusion
Node js:
var random = require('mk-randoms')
ES6:
import random from 'mk-randoms/dist/random.es6'
import random from 'mk-randoms' // this will work as well
Browser:
<script src="node_modules/mk-randoms/dist/random.min.js"></script>
Usage
random.num(min, max)
Random numerical value between min and max values.
random.int(min, max)
Random integer between min and max values.
random.ok([okProbability])
Random boolean. okProbability - is an optional probability of "TRUE" value percentage, dafault is 50.
random.str([length][, sourceStr])
Random string. length: is a length of string, dafault is 1. sourceStr: is a set of acceptable characters, default is "abcdefghijklmnopqrstuvwxyz"
random.element(arr[, quantity])
Random element of array, or array - random subset of sourse array, where every source element can be copied no more then one time. arr: source array. quantity: default is 1, if 1 returns random array element, otherwise it is a length of resulting array, if quantity is larger then source array length, then returns source array.
random.shift(val[, percentage])
Random shift of numerical value. val: original number. percentage: amplitude of discrepancy, default is 10.
random.intShift(val[, percentage])
Random integer shift of integer value. val: original number. percentage: amplitude of discrepancy, default is 10.