@oreefy/random
v1.0.0
Published
A tiny, fast, and cryptographically secure random string generator with zero dependencies. Supports unbiased randomness using crypto.getRandomValues and customizable character sets.
Maintainers
Readme
@oreefy/random
A lightweight, zero-dependency, cryptographically secure random string generator for JavaScript and TypeScript. Unlike Math.random(), it uses Web Crypto API (crypto.getRandomValues) to generate truly unbiased random strings, avoiding modulo bias. Perfect for generating secure tokens, passwords, OTPs, and unique IDs. Fully customizable with options for lowercase, uppercase, numbers, and special characters.
@oreefy/random is a library built for the Oreefy ecosystem. The package is officially developed, maintained, and fully controlled by Oreefy, ensuring long-term stability, consistency, and compatibility across the ecosystem.
Required Capabilities
- JavaScript / TypeScript
- Web Crypto API (
crypto)
Usage
import { random } from "@oreefy/random";
// Default - 4 characters with all charsets
random(); // -> 'aB3$'
// Generate with custom length
random(10); // -> 'xT9#kL2@pQ'
random(16); // -> 'aB3~dE7!gH1$kL90'
// Generate with specific character sets
random(8, { atoz: true }); // -> 'abcdefgh'
random(8, { atoz: true, AtoZ: true }); // -> 'aBcDeFgH'
random(6, { number: true }); // -> '482917'
random(12, { atoz: true, AtoZ: true, number: true, special: true }); // -> 'aB3$dE9@kL1!'API Reference
random(length?, options?)
| Parameter | Type | Default | Description |
| --------------- | ------- | ------- | ------------------------------------------------------------------------------ |
| length | number | 4 | The length of the generated string. Must be a positive integer. |
| options | object | all | charsets Character sets to include. If no options provided, all sets are used. |
| options.atoz | boolean | false | Include lowercase a-z |
| options.AtoZ | boolean | false | Include uppercase A-Z |
| options.number | boolean | false | Include numbers 0-9 |
| options.special | boolean | false | Include special characters ~!@#\$%^&\*()... ` |
Returns: string - A cryptographically secure random string.
About Oreefy
Oreefy is an affordable business ecosystem designed for small to enterprise businesses. Oreefy provides essential software you need for your modern business within a single ecosystem. It will save you significant time, effort, and money.
License
MIT © Oreefy
