1.0.9 • Published 5 years ago

random-nodejs v1.0.9

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

Node.js Random Numbers and String

A simple and flexible npm library that creates various type of Random Numbers and String. Works in both NodeJS and the browser.

Installation

npm i random-nodejs --save

Import

var rand = require("random-nodejs");

Numbers API

String API

random

Return, Random float numbers.

rand.random(baseNum, fixedNum);

baseNum represent base of the number system. Default is 1 Specified baseNum as 1, 10, 100, 1000 ... fixedNum represent max length of output float number.

rand.random(1, 5)     // Ex. output 0.41008,  0.89666

rand.random(10, 5)    // Ex. output 6.30851,  5.64046

rand.random(100, 5)   // Ex. output 44.75786, 30.95153

rand.random(1000, 3)  // Ex. output 422.649,   437.101

bool

Return, Random true or false values.

rand.bool(thresholdNum);

Specified thresholdNum between 0 and 1 Default is 0.5 When thresholdNum = 0.5, Get true => 50%, false => 50% When thresholdNum = 0.3, Get true => 30%, false => 70%

rand.bool(0.8)  // Ex. output true, true, true, false

rand.bool(0.2)  // Ex. output true, false, false, false

intnum

Return, Random integer numbers between min and max values.

rand.intnum(min, max);

Default min = 0 Default max = 1

rand.intnum(-5, 10)    // Ex. output 2 , 0, 3, -5

rand.intnum(-15, -5)   // Ex. output -4 , -10, -8, -5

floatnum

Return, Random float numbers between min and max values.

rand.floatnum(min, max, fixedNum);

Specified fixedNum to get max length of output float number. Default min = 0 Default max = 1

rand.floatnum(-5, 10, 5)   // Ex. output -4.92252, 9.29047, 9.30004, -2.33519

rand.floatnum(-5, 10, 2)   // Ex. output 1.56, -3.43 7.33

option

Return, Random numbers inside the user-defined array of numbers.

const arr = ([1, 2, 3, 4]);

random.option(arr);           // Ex. output 3, 1, 4, 1, 2

multiples

Return, Random numbers in multiples of a number(mutiples of mul value) in between min and max values.

rand.multiples(min, max, mul);

Default mul = 0.1 Default min = 0 Default max = 1

rand.multiples(-10, 10, 2)     // Ex. output -4, 6, -8, 10

rand.multiples(-10, 10, 0.2)   // Ex. output  10, -1.4, -2.8, 6.4

capital

Return, Capital letters.

rand.capital();

Ex. Output  A, Z, E, C ...

simple

Return, Simple letters.

rand.simple();

Ex. Output  g, j, l, o ...

words

Return, Random Words inside the user-defined array of words.

var things = ['Rock', 'Paper', 'Scissor'];
rand.words(things);

Ex. Output  Paper, Scissor, Rock, Rock ...

Contributing

You can contribute to this project. You just need to create a pull request which will be revised, merged to main branch (if the code doesn't break the project) and published as a new release.

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago