Requires C++23 (e.g., -std=c++23 for GCC/Clang, /std:c++latest for MSVC).


API Reference · Usage Guide · Releases
Features
- Core — Generate entities composed of user-defined components. Each component produces a typed random value accessible via
entity.get<T>(key). Register, remove, and generate with fluent chaining.
- Generic Components — Ready-made templates for common patterns:
constant_component<T>, choice_component<T>, range_component<T>, callback_component, and weighted_choice_component<T>. All accept an optional custom formatter.
- Randomness & Replay — Deterministic seeding at per-call and generator level. Every entity and component stores its seed for full replay via seed signatures.
- Advanced Generation — Batch generation (synchronous and concurrent), named component groups, selective generation by key subset, component weights for probabilistic inclusion, and conditional components for logic-driven inclusion via
should_generate(ctx).
- Validation & Hooks — Per-component
validate() with automatic retries, entity-level validator callbacks, and a generation_observer interface with 15 lifecycle hooks. Multiple observers can be attached simultaneously via add_observer / remove_observer.
- Extensions —
dasmig::ext::stats_observer tracks generation counts, skips, retries, and failures out of the box.
- ECS Integration — Optional adapter headers for EnTT and Flecs. Register key→component mappings, then
spawn() converts generated entities into typed ECS entities.
- Serialization —
entity.to_string(), operator<<, and entity.to_map() for structured key–value export.
- Composable & Thread-Safe — Components can wrap name-generator and nickname-generator. Independent
eg instances enable lock-free concurrent generation.
Integration
entitygen.hpp is the single required file released here. You need to add
The entity generator — produces entities with configurable components.
Entity generator library — composable, deterministic entity generation for C++23.
to the files you want to generate entities and set the necessary switches to enable C++23 (e.g., -std=c++23 for GCC and Clang).
The library makes use of a random generation library by effolkronium. For the convenience of the user, the header-only file containing the implementation was added to this repository.
Quick Start
Define a component by implementing the component interface:
{
public:
[[nodiscard]] std::wstring
key()
const override {
return L
"class"; }
{
static const std::vector<std::wstring> classes{
L"Warrior", L"Mage", L"Rogue", L"Healer"};
return ctx.
random().get(classes);
}
[[nodiscard]] std::wstring
to_string(
const std::any& value)
const override
{
}
};
{
public:
[[nodiscard]] std::wstring
key()
const override {
return L
"age"; }
{
return ctx.
random().get(18, 65);
}
[[nodiscard]] std::wstring
to_string(
const std::any& value)
const override
{
}
};
Abstract base for entity components.
virtual std::any generate(const generation_context &ctx) const =0
Generate a random value for this component.
virtual std::wstring to_string(const std::any &value) const =0
Convert a generated value to a displayable string.
static std::wstring default_to_string(const std::any &value)
Default conversion covering common standard types.
virtual std::wstring key() const =0
Unique key identifying this component (e.g. "name", "age").
Context passed to components during generation.
effolkronium::random_local & random() const
Access the random engine for this generation.
Register components and generate entities:
eg::instance()
.
add(std::make_unique<character_class>())
.
add(std::make_unique<age>());
std::wcout << eg::instance().
generate() << std::endl;
auto entity = eg::instance().generate();
std::wstring cls = entity.
get<std::wstring>(L
"class");
int char_age = entity.get<int>(L"age");
auto seeded = eg::instance().generate(42);
entity generate()
Generate an entity with all registered components.
eg & add(std::unique_ptr< component > comp)
Register a component.
T get(const std::wstring &component_key) const
Typed retrieval of a component value by key.
For the complete feature guide — component dependencies, custom types, seed signatures, batch generation, groups, weights, validation, event hooks, extensions, and more — see the Usage Guide.
For planned features — Python/Node.js/.NET wrappers and more — see the Roadmap.