npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

random-gen-utils

v1.0.0

Published

A comprehensive utility package for generating random strings, passwords, colors, and numbers with customizable options

Readme

🎲 Random Generator Utils

A lightweight, zero-dependency utility package for generating random strings, passwords, colors, and numbers with customizable options.

📦 Installation

npm install random-gen-utils

🚀 Quick Start

const randomGen = require('random-gen-utils');

// Generate random string
const str = randomGen.randomString(10);

// Generate random password
const pwd = randomGen.randomPassword(16);

// Generate random color
const color = randomGen.randomColor('hex');

// Generate random number
const num = randomGen.randomNumber(1, 100);

📖 API Reference

randomString(length, type)

Generate a random string with specified length and character type.

Parameters:

  • length (number, optional): Length of the string. Default: 10
  • type (string, optional): Type of characters - 'alphanumeric', 'alpha', or 'numeric'. Default: 'alphanumeric'

Returns: string

Examples:

randomGen.randomString();              // "aB3xK9mP2q" (10 chars, alphanumeric)
randomGen.randomString(20);            // 20 character alphanumeric string
randomGen.randomString(15, 'alpha');   // "AbCdEfGhIjKlMnO" (15 chars, letters only)
randomGen.randomString(8, 'numeric');  // "12345678" (8 chars, numbers only)

randomPassword(length, options)

Generate a secure random password with customizable character types.

Parameters:

  • length (number, optional): Length of the password. Default: 12
  • options (object, optional): Password options
    • uppercase (boolean): Include uppercase letters A-Z. Default: true
    • lowercase (boolean): Include lowercase letters a-z. Default: true
    • numbers (boolean): Include numbers 0-9. Default: true
    • symbols (boolean): Include special symbols. Default: true

Returns: string

Examples:

randomGen.randomPassword();                    // "aB3#xK9@mP2!" (12 chars, all types)
randomGen.randomPassword(16);                  // 16 character password with all types
randomGen.randomPassword(20, {
  uppercase: true,
  lowercase: true,
  numbers: true,
  symbols: false
});                                            // 20 char password without symbols

randomColor(format)

Generate a random color in various formats.

Parameters:

  • format (string, optional): Color format - 'hex', 'rgb', 'hsl', or 'array'. Default: 'hex'

Returns: string or array (depending on format)

Examples:

randomGen.randomColor();           // "#a3f5b2" (HEX format)
randomGen.randomColor('rgb');      // "rgb(163, 245, 178)"
randomGen.randomColor('hsl');      // "hsl(132, 85%, 80%)"
randomGen.randomColor('array');    // [163, 245, 178]

randomNumber(min, max, decimal, precision)

Generate a random number within a specified range.

Parameters:

  • min (number, optional): Minimum value. Default: 0
  • max (number, optional): Maximum value. Default: 100
  • decimal (boolean, optional): Return decimal/float number. Default: false
  • precision (number, optional): Decimal places for floats. Default: 5

Returns: number

Examples:

randomGen.randomNumber();                    // 42 (integer between 0-100)
randomGen.randomNumber(1, 10);               // 7 (integer between 1-10)
randomGen.randomNumber(0, 1, true);          // 0.72341 (decimal between 0-1)
randomGen.randomNumber(0, 100, true, 2);     // 42.56 (decimal with 2 places)

💡 Usage Examples

Generate Test Data

const testUsers = Array.from({ length: 10 }, (_, i) => ({
  id: randomGen.randomString(8),
  username: `user_${randomGen.randomNumber(1000, 9999)}`,
  password: randomGen.randomPassword(16),
  favoriteColor: randomGen.randomColor('hex')
}));

Create Session IDs

const sessionId = randomGen.randomString(32, 'alphanumeric');

Generate API Keys

const apiKey = randomGen.randomPassword(64, {
  uppercase: true,
  lowercase: true,
  numbers: true,
  symbols: false
});

Random UI Theming

const theme = {
  primary: randomGen.randomColor('hex'),
  secondary: randomGen.randomColor('hex'),
  accent: randomGen.randomColor('rgb'),
  opacity: randomGen.randomNumber(50, 100, true, 2) / 100
};

Express.js Route Example

const express = require('express');
const randomGen = require('random-gen-utils');
const app = express();

app.get('/api/random-color', (req, res) => {
  res.json({ 
    color: randomGen.randomColor('hex'),
    rgb: randomGen.randomColor('rgb')
  });
});

app.listen(3000);

🌐 TypeScript Support

While this package is written in JavaScript, you can use it in TypeScript projects:

import * as randomGen from 'random-gen-utils';

const password: string = randomGen.randomPassword(16);
const num: number = randomGen.randomNumber(1, 10);

✨ Features

  • ✅ Zero dependencies - Lightweight and fast
  • ✅ CommonJS support - Works in Node.js projects
  • ✅ Customizable options - Fine-tune output to your needs
  • ✅ Multiple formats - Colors in HEX, RGB, HSL, or array
  • ✅ Secure passwords - Customizable character sets
  • ✅ Well documented - Clear examples and API docs

📝 License

MIT License - see LICENSE file for details


🤝 Contributing

Contributions, issues, and feature requests are welcome!


👤 Author

Rakesh Kumar


🙏 Support

Give a ⭐️ if this project helped you!