Documentation
    Preparing search index...

    Namespace RandomGenerator

    Comprehensive random data generation utilities for testing and development.

    RandomGenerator provides a collection of functions for generating random data including strings, names, content, dates, and array sampling. All functions draw from Math.random(), so they are not seeded and produce varied output across executions, which suits testing scenarios that need arbitrary data.

    The namespace includes specialized generators for:

    • Text content (alphabets, alphanumeric, names, paragraphs)
    • Phone numbers and contact information
    • Date ranges and time-based data
    • Array sampling and element selection

    Processing cost: Text construction scales with generated characters, sparse sampling with selected positions, and fixed-size draws use constant work. The namespace retains only fixed character tables; each generator owns its invocation-local result.

    Jeongho Nam - https://github.com/samchon

    // Generate test user data
    const testUser = {
    id: RandomGenerator.alphaNumeric(8),
    name: RandomGenerator.name(),
    bio: RandomGenerator.paragraph({
    sentences: 3,
    wordMin: 5,
    wordMax: 10,
    }),
    phone: RandomGenerator.mobile(),
    createdAt: RandomGenerator.date(new Date(), 1000 * 60 * 60 * 24 * 30), // 30 days
    };

    // Sample data for testing
    const testSample = RandomGenerator.sample(allUsers, 5);

    contracts/common.md#principled-implementation The private integer helper partitions Math.random output into equally sized bins for finite ordered integer bounds, and generators compose text, dates and selections from those draws. Math.random is approximately uniform and not cryptographically secure; exact probability guarantees do not follow from its finite precision.

    contracts/common.md#clear-and-simple-design Small generators build on each other (name on paragraph, content on paragraph, both on alphabets), so one integer helper decides the randomness.

    contracts/common.md#prohibited-implementation-shortcuts The data are drawn, not taken from a fixed list of test values.

    contracts/common.md#meaningful-documentation The namespace prose says the functions are not seeded and lists the kinds of data, with an example.

    alphabets
    alphaNumeric
    content
    date
    mobile
    name
    paragraph
    pick
    sample
    substring