@marcuth/random
v0.1.0
Published
Random utilities
Readme
@marcuth/random
A lightweight TypeScript library providing simple random utility functions.
Features
- Integer Generation: Generate random integers within a specific range.
- Float Generation: Generate random floating-point numbers within a specific range.
- Array Picking: Randomly select an item from an array.
- TypeScript Support: Written in TypeScript with full type definitions.
Installation
Install the package via npm:
npm install @marcuth/randomUsage
Import the default random object to access all utilities:
import random from '@marcuth/random';
// Generate a random int between 1 and 10 (inclusive)
const myInt = random.int(1, 10);
console.log(myInt);
// Generate a random float between 0 and 1
const myFloat = random.float(0, 1);
console.log(myFloat);
// Pick a random item from an array
const fruits = ['apple', 'banana', 'cherry'];
const randomFruit = random.pick(fruits);
console.log(randomFruit);API Reference
random.int(min: number, max: number): number
Returns a random int between min and max (inclusive).
- min: The minimum value.
- max: The maximum value.
random.float(min: number, max: number): number
Returns a random floating-point number between min and max.
- min: The minimum value.
- max: The maximum value.
random.pick<T>(items: T[]): T
Returns a random element from the provided array.
- items: An array of items of type
T.
License
MIT
