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.
// Generate test user data consttestUser = { id:RandomGenerator.alphaNumeric(8), name:RandomGenerator.name(), bio:RandomGenerator.paragraph({ sentences:3, wordMin:5, wordMax:10, }), phone:RandomGenerator.mobile(), createdAt:RandomGenerator.date(newDate(), 1000 * 60 * 60 * 24 * 30), // 30 days };
// Sample data for testing consttestSample = RandomGenerator.sample(allUsers, 5);
Evidence
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.
Evidence
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.
Evidence
contracts/common.md#prohibited-implementation-shortcuts The data are drawn, not taken from a fixed list of test values.
Evidence
contracts/common.md#meaningful-documentation The namespace prose says the functions are not seeded and lists the kinds of data, with an example.
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:
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.
Author
Jeongho Nam - https://github.com/samchon
Example
Evidence
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.
Evidence
contracts/common.md#clear-and-simple-design Small generators build on each other (
nameonparagraph,contentonparagraph, both onalphabets), so one integer helper decides the randomness.Evidence
contracts/common.md#prohibited-implementation-shortcuts The data are drawn, not taken from a fixed list of test values.
Evidence
contracts/common.md#meaningful-documentation The namespace prose says the functions are not seeded and lists the kinds of data, with an example.