Skip to content

Mock Data Generator — C++ 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 C++ implementation — the same logic the interactive tool runs, in a shareable, citable form.

// mock-data-generator — C++ 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; uint32_t wrap-around stands in for
// the JS `|0` / `>>>` / Math.imul semantics, so a seed rebuilds the same rows.
#include <cstdint>
#include <iostream>
#include <string>
#include <string_view>

namespace {

constexpr std::string_view kFirst[] = {"Ava",    "Liam",  "Noah",   "Emma",
                                       "Olivia", "Aiden", "Sophia", "Mason"};
constexpr std::string_view kLast[] = {"Smith", "Johnson", "Williams", "Brown",
                                      "Jones", "Garcia",  "Miller",   "Davis"};

// Mutable lambda captures the state: draws happen in schema order, mirroring
// the TS lib's closure.
auto mulberry32(std::uint32_t seed) {
    return [a = seed]() -> double {
        a += 0x6D2B79F5u;
        std::uint32_t t = (a ^ (a >> 15)) * (1u | a); // Math.imul: uint wraps
        t = (t + (t ^ (t >> 7)) * (61u | t)) ^ t;
        return static_cast<double>(t ^ (t >> 14)) / 4294967296.0;
    };
}

std::string to_lower(std::string_view s) {
    std::string out(s);
    for (char &c : out)
        if (c >= 'A' && c <= 'Z')
            c = static_cast<char>(c - 'A' + 'a');
    return out;
}

template <std::size_t N>
std::string_view pick(const std::string_view (&names)[N], double r) {
    return names[static_cast<std::size_t>(r * N)];
}

} // namespace

int main() {
    auto rand = mulberry32(1234); // seed

    std::cout << "[\n";
    for (int i = 0; i < 3; ++i) { // count
        // email: two draws, like the TS reference
        std::string email = to_lower(pick(kFirst, rand())) + "." +
                            to_lower(pick(kLast, rand())) + "@example.com";
        int age = 18 + static_cast<int>(rand() * (65 - 18 + 1)); // integer
        bool active = rand() < 0.5;                              // boolean
        std::cout << "  {\"id\": " << i << ", \"email\": \"" << email
                  << "\", \"age\": " << age
                  << ", \"active\": " << (active ? "true" : "false") << "}"
                  << (i < 2 ? "," : "") << "\n";
    }
    std::cout << "]\n";
    return 0;
}

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 →