Random
Get random
Install
npm i @hikyu/random
Usage
I will use the deconstructed
// Simple require
const random = require('@hikyu/random');
random.number(1, 10); // > 4
// Deconstructed require with custom names
const { number: ranNumber } = require('@hikyu/random');
ranNumber(1, 10); // > 4
// Deconstructed require
const { number, index, value, .. } = require('@hikyu/random');
number(1, 10); // > 4
Functions
π’
Numbers Digit
// Random number from 0 to 9
digit(); // > 8
// Random number from 0 to 4
digit(4); // > 1
Integer
// Random integer from 1 to 10
number(1, 10); // > 4
Decimal number
// Random number from 1 to 10 with 2 decimal spaces
number(1, 10, 2); // > 5.19
Boolean
// Generates either true or false
boolean(); // > false
π
Array Index of array
// Random index out of the array
index(["hello", "world", 1]); // > 1
Value of array
// Random value out of the array
value("hello", "world", 1); // > "hello"
π€¨
Misc Template
Meaning | Charcode | Outputs |
---|---|---|
Any | a | Any of the below |
Char | c | Lowercase char |
Char | C | Uppercase char |
Char | s | Upper or lowercase char |
Digit | d | Digit 0-9 |
Digit | 0-9 | Digit up to value |
Escape | $ | Escape the next char |
// Generate template string
template('aaaaa'); // > "6qxsF"
template('ccccc'); // > "htcfi"
template('CCCCC'); // > "UNHCG"
template('sssss'); // > "ZaSrV"
template('ddddd'); // > "54628"
template('00033'); // > "00031"
template('ccc - $3 $Ch$ar$a$cters'); // > "zpb - 3 Characters"
// Password example
template('sdssdssdsssdd'); // > d5pi7tI7vWr85
// Byte example
template('1111 1111'); // > 0101 1101
// Telephone example
template('ddd-ddd-dddd'); // > 607-321-8576
Color - RGB
// Random RGB color as string
rgb(); // > "rgb(66, 193, 254)"
Color - RGBA
// Random RGB color as string
rgba(); // > "rgba(251, 41, 72, 0.47)"
Color - HEX
// Random RGB color as string
hex(); // > "#6c7ac4"
Color - HSL
// Random HSL color as string
hsl(); // > "hsl(153, 44%, 64%)"
Emoji
// Random Emoji
emoji(); // > "π"
π²
Dice // Generate 3 values from 1 to 20
dice(20, 3); // > [ 2, 7, 11 ]
Byte
// Generate 3 values from 1 to 20
byte(); // > "0101 1110"
Bit
// Generate 0 or 1
bit(); // > 0