https://github.com/shahradelahi/rand
Random string and number generator.
https://github.com/shahradelahi/rand
javascript random uuidv4
Last synced: about 1 year ago
JSON representation
Random string and number generator.
- Host: GitHub
- URL: https://github.com/shahradelahi/rand
- Owner: shahradelahi
- License: mit
- Created: 2024-06-28T08:11:19.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-03-29T08:06:20.000Z (about 1 year ago)
- Last Synced: 2025-03-29T09:20:18.528Z (about 1 year ago)
- Topics: javascript, random, uuidv4
- Language: TypeScript
- Homepage: https://npmjs.com/@se-oss/rand
- Size: 79.1 KB
- Stars: 80
- Watchers: 2
- Forks: 0
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @se-oss/rand
[](https://github.com/shahradelahi/rand/actions/workflows/ci.yml)
[](https://www.npmjs.com/package/@se-oss/rand)
[](/LICENSE)
[](https://packagephobia.com/result?p=@se-oss/rand)
This library provides functions for generating random strings and numbers in various formats, including Base10, Base36, Base62, UUIDv4, and random numbers within specified ranges or lengths.
---
- [Installation](#-installation)
- [Usage](#-usage)
- [Documentation](#-documentation)
- [Contributing](#-contributing)
- [License](#license)
## 📦 Installation
```bash
pnpm i @se-oss/rand
```
## 📖 Usage
```typescript
import * as rnd from '@se-oss/rand';
// Generate a random Base62 string of length 12
console.log(rnd.randomBase62(12)); // Example output: 'A1b2C3d4E5f6'
// Generate a random Base36 string of length 8
console.log(rnd.randomBase36(8)); // Example output: '1a2b3c4d'
// Generate a random Base10 string of length 4
console.log(rnd.randomBase10(4)); // Example output: '5678'
// Generate a random UUIDv4 string
console.log(rnd.randomUuidv4()); // Example output: 'f81d4fae-7dec-11d0-a765-00a0c91e6bf6'
// Generate a random number between 1 and 10
console.log(rnd.randomNumber(1, 10)); // Example output: 5
// Generate a random number of length 16
console.log(rnd.randomNumber(16)); // Example output: 8933580352864351
```
## 📚 Documentation
For all configuration options, please see [the API docs](https://www.jsdocs.io/package/@se-oss/rand).
##### API
```typescript
// Generates a random string of a specified length using the provided characters.
function random(chars: string, length: number): string;
// Generates a random string of a specified length using Base62 characters (A-Z, a-z, 0-9).
function randomBase62(length: number): string;
// Generates a random string of a specified length using Base36 characters (a-z, 0-9).
function randomBase36(length: number): string;
// Generates a random string of a specified length using Base10 characters (0-9).
function randomBase10(length: number): string;
// Generates a random UUIDv4 string.
function randomUuidv4(): string;
// Generates a random number within a specified range or of a specified length.
function randomNumber(min: number, max: number): number;
function randomNumber(length: number): number;
```
## 🤝 Contributing
Want to contribute? Awesome! To show your support is to star the project, or to raise issues on [GitHub](https://github.com/shahradelahi/rand).
Thanks again for your support, it is much appreciated! 🙏
## License
[MIT](/LICENSE) © [Shahrad Elahi](https://github.com/shahradelahi) and [contributors](https://github.com/shahradelahi/rand/graphs/contributors).