Cette page est affichée en anglais. Une traduction française est en cours.
ConfigsJul 22, 2026·3 min de lecture

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.

Prêt pour agents

Staging sûr pour cet actif

Cet actif est d'abord staged. Le prompt copié demande à l'agent d'inspecter les fichiers staged avant d'activer scripts, config MCP ou config globale.

Stage only · 17/100Policy : staging
Surface agent
Tout agent MCP/CLI
Type
Script
Installation
Stage only
Confiance
Confiance : Established
Point d'entrée
Chance.js
Commande de staging sûr
npx -y tokrepo@latest install f313cf9b-8565-11f1-9bc6-00163e2b0d79 --target codex

Stage les fichiers d'abord; l'activation exige la revue du README et du plan staged.

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

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires