A lightweight utility library for generating pseudo-random values in JavaScript based of `Math.random()`.
npm install @kottetall/randomMath.random().
bash
npm install @kottetall/random
`
Usage
$3
`js
import { Random } from "@kottetall/random";
console.log(Random.firstName()); // Jack
console.log(Random.firstName("female")); // Sofia
console.log(Random.lastName()); // White
console.log(Random.fullName()); // Jack Hassan
`
$3
Generates a random string using two strings as per-character boundaries.
Instead of choosing one of the input strings, the method treats them as limits for each character position. For every index, it determines the range between the corresponding characters in the two strings and randomly selects a character within that range.
Each character in the resulting string is generated independently, which allows the method to produce combinations that do not exist in either of the original strings.
`js
import { Random } from "@kottetall/random";
const stringA = "a2";
const stringB = "b1";
const result = Random.arbitraryString(stringA, stringB);
console.log(result); // "a1" | "b1" | "a2" | "b2"
`
$3
`js
import { Random } from "@kottetall/random";
const items = ["apple", "banana", "orange"];
const result = Random.fromArray(items);
console.log(result); // "banana"
`
$3
`js
import { Random } from "@kottetall/random";
const obj = {
a: 1,
b: 2,
c: 3,
};
const result = Random.fromObject(obj);
console.log(result); // 3
``