@ts-utilkit/random
v0.1.1
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)
randomInt- Generates a random integer within a rangerandomFloat- Generates a random floating-point number within a rangerandomBoolean- Generates a random boolean valuerandomElement- Selects a random element from an arrayrandomElements- Selects multiple random elements from an arrayrandomString- Generates a random string of specified lengthrandomHex- Generates a random hexadecimal stringrandomUUID- Generates a random UUID (v4)randomColor- Generates a random color in hex formatrandomRGB- Generates a random RGB color objectrandomDate- Generates a random date within a rangerandomChoice- Makes a random choice based on weighted probabilitiesshuffleArray- Randomly shuffles an array (Fisher-Yates algorithm)randomSample- Takes a random sample of specified size from an arrayrandomPassword- Generates a random password with configurable optionsrandomAlphanumeric- Generates a random alphanumeric stringrandomDigits- Generates a random string of digitsrandomLetters- Generates a random string of lettersrandomBytes- Generates cryptographically secure random bytesrandomIntCrypto- Generates a cryptographically secure random integerrandomFloatCrypto- Generates a cryptographically secure random floatrandomIP- Generates a random IP address (IPv4 or IPv6)randomMACAddress- Generates a random MAC addressrandomPhoneNumber- Generates a random phone numberrandomEmail- Generates a random email address
Usage Examples
import { randomInt, randomElement, randomPassword, shuffleArray } from '@ts-utilkit/random';
// Random integer
const dice = randomInt(1, 6);
// Result: Random number between 1 and 6
// Random element from array
const fruits = ['apple', 'banana', 'orange'];
const randomFruit = randomElement(fruits);
// Result: One random fruit
// Secure password generation
const password = randomPassword(16, { uppercase: true, numbers: true, symbols: true });
// Result: "aB7#kL9$pQ2@mN5!"
// Shuffle array
const cards = [1, 2, 3, 4, 5];
const shuffled = shuffleArray(cards);
// Result: [3, 1, 5, 2, 4] (random order)API Documentation
For complete API documentation, please visit the main repository.
License
MIT © MForofontov
Contributing
Contributions are welcome! Please see the main repository for contribution guidelines.
