@ts-utilkit/random
v0.2.0
Published
Random generation utilities for numbers, strings, arrays, and weighted selections
Maintainers
Readme
@ts-utilkit/random
random Functions - TypeScript utility functions for random operations.
Installation
npm install @ts-utilkit/randomFeatures
- 🚀 TypeScript-first with complete type definitions
- ✅ Comprehensive test coverage (>95%)
- 📦 Tree-shakeable ESM and CommonJS support
- 🔒 Type-safe with strict TypeScript configuration
- 📖 Extensive JSDoc documentation
Available Functions (25)
loremIpsum- Generates Lorem Ipsum placeholder textrandomBase64- Generates a random Base64 encoded stringrandomBetween- Generates a random number between min and maxrandomBoolean- Generates a random boolean valuerandomChoice- Selects a random element from an array (alias for randomElement)randomColorFromPalette- Selects a random color from a predefined paletterandomDate- Generates a random date within a rangerandomElement- Selects a random element from an arrayrandomEnum- Selects a random value from an enumrandomFloat- Generates a random floating-point number within a rangerandomFromRange- Generates a random number from a specified rangerandomHex- Generates a random hexadecimal stringrandomHexColor- Generates a random color in hex formatrandomInt- Generates a random integer within a rangerandomPattern- Generates a string matching a patternrandomPercentage- Generates a random percentage valuerandomRGB- Generates a random RGB color objectrandomSample- Takes a random sample of specified size from an arrayrandomSequence- Generates a random sequence of numbersrandomShuffle- Randomly shuffles an array (Fisher-Yates algorithm)randomSubset- Selects a random subset from an arrayrandomUUID- Generates a random UUID (v4)randomWeighted- Makes a weighted random choicerandomWord- Generates a random wordrandomWords- Generates multiple random words
Quick Example
import {
randomInt,
randomFloat,
selectRandom,
shuffleArray,
} from '@ts-utilkit/random';
randomInt(1, 6); // 4
randomFloat(0, 1); // 0.7234
selectRandom(['a', 'b', 'c']); // 'b'
shuffleArray([1, 2, 3, 4]); // [3, 1, 4, 2]License
MIT © Mykyta Forofontov
Contributing
Contributions are welcome! Please see the main repository for contribution guidelines.
