Generate random strings, numbers, hex, alphanumeric, pick, shuffle, and more.
import { random } from 'toolmetry';| Function | Parameters | Returns | Description |
|---|---|---|---|
randomString | length?: number, options?: object | string | Generate a random string with options |
randomInt | min: number, max: number | number | Random integer between min and max |
randomHex | length?: number | string | Generate a random hex string |
randomAlphanumeric | length?: number | string | Generate a random alphanumeric string |
randomPick | array: Array | any | Pick a random element from an array |
randomShuffle | array: Array | Array | Shuffle an array (Fisher-Yates) |
randomBoolean | — | boolean | Generate a random boolean |
randomFloat | min: number, max: number, decimals?: number | number | Random float between min and max |
import { randomString } from 'toolmetry';
const str = randomString(16, { lowercase: true, uppercase: true, digits: true });
// "aB3xY9kL2mN5pQ8"
const simple = randomString(8, { digits: true, symbols: false });
// "aB3xY9kL"import { randomInt, randomFloat } from 'toolmetry';
const int = randomInt(1, 100); // e.g. 42
const float = randomFloat(0, 1, 4); // e.g. 0.5321import { randomHex, randomAlphanumeric } from 'toolmetry';
const hex = randomHex(32);
// "a1b2c3d4e5f6..."
const alpha = randomAlphanumeric(16);
// "aB3xY9kL2mN5pQ8"import { randomPick, randomShuffle } from 'toolmetry';
const picked = randomPick(['apple', 'banana', 'cherry']);
// "banana"
const shuffled = randomShuffle([1, 2, 3, 4, 5]);
// [3, 1, 5, 2, 4]