random-any
v1.0.0
Published
Generate random stuff
Readme
random-any
A simple, fast, and flexible random value generator for JavaScript and TypeScript.
Supports both class and instance usage. Built with Bun, works in Node.js and modern browsers.
Features
- Generate random integers, floats, booleans, strings, array elements, and dates
- Use as a class or a ready-to-use instance
- TypeScript types included
- Lightweight and dependency-free
Installation
bun install random-any
# or
npm install random-any
# or
yarn add random-any
## Usage
```typescript
// Using as a class
import Random from 'random-any';
const random = new Random();
// Using as a ready-to-use instance
import { random } from 'random-any';
random.randomInt(1, 10)
random.randomFloat(1, 10)
random.randomString(10)
random.randomBoolean()
random.randomArrayElement([1, 2, 3, 4])
random.randomDate(new Date('2020-01-01'), new Date('2020-12-31'))API
randomInt(min?: number, max?: number): numberReturns a random integer between min and max (inclusive).
randomFloat(min?: number, max?: number): numberReturns a random float between min and max.
randomBoolean(): booleanReturns a random boolean value.
randomString(length: number): stringReturns a random alphanumeric string of the given length.
randomArrayElement<T>(array: T[]): TReturns a random element from the given array.
randomDate(start: Date, end: Date): DateReturns a random date between the start and end dates.
Testing
bun testBuild
bun run buildLicense
MIT
