Mock Data Generator — Java source
Generate deterministic fake data (names, emails, numbers, dates, booleans, UUIDs, pick-from-list) from a schema and a seed. Reproducible output.
This is the Java implementation — the same logic the interactive tool runs, in a shareable, citable form.
// mock-data-generator — Java port of the CosmoDev tool.
// The seeded mulberry32 PRNG (bit-identical to src/lib/mockData.ts and the Go
// twin) drives a representative field set; int arithmetic already wraps mod
// 2^32 (the Math.imul semantics) and >>> supplies the unsigned shift.
import java.util.LinkedHashMap;
import java.util.Map;
public class MockDataGenerator {
static final String[] FIRST =
{ "Ava", "Liam", "Noah", "Emma", "Olivia", "Aiden", "Sophia", "Mason" };
static final String[] LAST =
{ "Smith", "Johnson", "Williams", "Brown", "Jones", "Garcia", "Miller", "Davis" };
/** PRNG with carried state so draws stay in schema order (the TS closure). */
static final class Rng {
private int a;
Rng(int seed) { this.a = seed; }
double next() {
a += 0x6D2B79F5; // wraps: int is mod 2^32
int t = (a ^ (a >>> 15)) * (1 | a); // == Math.imul here
t = (t + (t ^ (t >>> 7)) * (61 | t)) ^ t;
return ((t ^ (t >>> 14)) & 0xFFFFFFFFL) / 4294967296.0; // unsigned
}
}
/** Representative fields from the schema dispatch in mockData.ts. */
static Object field(String type, int index, Rng rng, int min, int max) {
switch (type) {
case "index":
return index; // no draw
case "email": { // two draws, like TS
String f = FIRST[(int) (rng.next() * FIRST.length)].toLowerCase();
String l = LAST[(int) (rng.next() * LAST.length)].toLowerCase();
return f + "." + l + "@example.com";
}
case "integer":
return min + (int) (rng.next() * (max - min + 1));
case "boolean":
return rng.next() < 0.5;
default:
return null; // unknown type -> null
}
}
public static void main(String[] args) {
Rng rng = new Rng(1234); // seed
String[][] schema = { // name, type, min, max
{ "id", "index", "0", "0" },
{ "email", "email", "0", "0" },
{ "age", "integer", "18", "65" },
{ "active", "boolean", "0", "0" },
};
for (int i = 0; i < 3; i++) { // count
Map<String, Object> row = new LinkedHashMap<>(); // insertion order
for (String[] spec : schema)
row.put(spec[0], field(spec[1], i, rng,
Integer.parseInt(spec[2]), Integer.parseInt(spec[3])));
System.out.println(row);
}
}
}
Also available in 13 other languages
Every CosmoDev tool ships its pure logic in TypeScript (web) and Go (CLI), with authored implementations in a dozen-plus languages — the same contract, ported. Compare all languages side by side →