ConfigsJul 22, 2026·3 min read

Chance.js — Random Data Generator for JavaScript

Lightweight utility library for generating random strings, numbers, names, addresses, dates and other test data in JavaScript and Node.js.

Agent ready

Safe staging for this asset

This asset is staged first. The copied prompt tells the agent to inspect the staged files and ask before activating scripts, MCP config, or global config.

Stage only · 17/100Policy: stage
Agent surface
Any MCP/CLI agent
Kind
Script
Install
Stage only
Trust
Trust: Established
Entrypoint
Chance.js
Safe staging command
npx -y tokrepo@latest install f313cf9b-8565-11f1-9bc6-00163e2b0d79 --target codex

Stages files first; activation requires review of the staged README and plan.

Introduction

Chance.js is a minimalist random data generator for JavaScript. It produces realistic random values for names, addresses, phone numbers, dates, strings, and many other data types, making it useful for testing, prototyping, and seeding development databases.

What Chance.js Does

  • Generates random personal data: names, emails, phone numbers, addresses, and SSNs
  • Produces random primitives: integers, floats, booleans, strings, and characters
  • Creates random dates, timestamps, and time-related values
  • Provides domain-specific generators for colors, coordinates, IP addresses, and credit cards
  • Supports seeded randomness for reproducible test data across runs

Architecture Overview

Chance.js is a single-file library with no external dependencies. It uses a Mersenne Twister pseudorandom number generator internally, which provides high-quality distribution and supports seeding. All generator methods are attached to a Chance instance, and each instance can be independently seeded. The library is designed for both browser and Node.js environments.

Self-Hosting & Configuration

  • Install via npm or include directly via a script tag in the browser
  • Create a Chance instance with an optional seed for reproducible output
  • Call generator methods with optional configuration objects to constrain output
  • Use chance.mixin() to register custom generator functions
  • Supports UMD, CommonJS, and ES module import styles

Key Features

  • Seeded random number generator for deterministic, reproducible test data
  • Wide variety of built-in generators covering personal data, finance, geography, and web
  • Zero dependencies with a small footprint suitable for browser and server
  • Mixin system for extending with custom data generators
  • Configurable output ranges and formats for most generator methods

Comparison with Similar Tools

  • Faker.js — larger library with locale support and more data types; Chance.js is lighter with built-in seeding
  • casual — similar scope but less actively maintained; Chance.js has broader generator coverage
  • falso — modern Faker alternative with tree-shaking; Chance.js offers a simpler single-instance API
  • randexp — generates strings matching a regex; Chance.js provides structured data types, not pattern-based
  • Fishery — factory-based test data with associations; Chance.js focuses on individual random values

FAQ

Q: How do I generate the same random data across test runs? A: Pass a seed to the constructor: new Chance(42). The same seed always produces the same sequence of values.

Q: Can I use Chance.js in the browser? A: Yes. Include it via a script tag or import it with a bundler. It has no Node.js-specific dependencies.

Q: How do I add custom generators? A: Use chance.mixin({ myGenerator: function() { return ...; } }) to add new methods to the instance.

Q: Does Chance.js support internationalized data? A: Chance.js focuses on English-language data. For localized names and addresses, consider Faker.js which has extensive locale support.

Sources

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets