Mock Data Generator — Kotlin 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 Kotlin implementation — the same logic the interactive tool runs, in a shareable, citable form.
// mock-data-generator — Kotlin 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 wraps mod 2^32 (the
// Math.imul semantics) and ushr supplies the unsigned shift.
val FIRST = listOf("Ava", "Liam", "Noah", "Emma", "Olivia", "Aiden", "Sophia", "Mason")
val LAST = listOf("Smith", "Johnson", "Williams", "Brown", "Jones", "Garcia", "Miller", "Davis")
/** Closure carries the state, mirroring the TS lib's consumption order. */
fun mulberry32(seed: Int): () -> Double {
var a = seed
return {
a += 0x6D2B79F5 // wraps: Int is mod 2^32
var t = (a xor (a ushr 15)) * (1 or a) // == Math.imul here
t = (t + (t xor (t ushr 7)) * (61 or t)) xor t
((t xor (t ushr 14)).toLong() and 0xFFFFFFFFL) / 4294967296.0 // unsigned
}
}
/** Representative fields from the schema dispatch in mockData.ts. */
fun field(
type: String,
index: Int,
rand: () -> Double,
min: Int = 0,
max: Int = 100,
): Any? = when (type) {
"index" -> index // no draw
"email" -> { // two draws, like TS
val f = FIRST[(rand() * FIRST.size).toInt()].lowercase()
val l = LAST[(rand() * LAST.size).toInt()].lowercase()
"$f.$l@example.com"
}
"integer" -> min + (rand() * (max - min + 1)).toInt()
"boolean" -> rand() < 0.5
else -> null // unknown type -> null
}
fun main() {
val rand = mulberry32(1234) // seed
data class Spec(val name: String, val type: String, val min: Int = 0, val max: Int = 0)
val schema = listOf(
Spec("id", "index"),
Spec("email", "email"),
Spec("age", "integer", 18, 65),
Spec("active", "boolean"),
)
repeat(3) { i -> // count
val row = schema.associate { it.name to field(it.type, i, rand, it.min, it.max) }
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 →