![]() |
Country Generator 3.3.2
Procedural country generation for C++23
|
Requires C++23 (e.g.,
-std=c++23for GCC/Clang,/std:c++latestfor MSVC).
API Reference · Usage Guide · Data and Method · Releases
Countries drawn by population, with names, codes, capital, region, languages, currency and other fields, and each country's locales, time zones, currencies and public holidays.
get_country({.region = "Europe"}).country_request with get_country(request) or get_country(request, seed) to choose a region and population-weighted or uniform selection. Population weighting remains the request default; no mutable generator selection settings are needed.find_country("US").en-CA, fr-CA) drawn by speakers, with Unicode CLDR's date, time, number and currency formats, names, week and measurement system, and format_date, format_time, format_number and format_money that use them.Asia/Calcutta) are followed.is_holiday. Rules inferred from python-holidays and checked against it for every country and year.core::money.get_country(request, seed) for reproducible results, and country::seed() for replaying a previous generation with the same request.extend()), checked before they are applied.to_json() on every result, and a signature() recording the seed and the data it came from.DASMIG_COUNTRY_EMBED to build the lite tier's countries into the program, for WebAssembly and other builds without files, and DASMIG_COUNTRY_EMBED_LOCALE to add its locale tables.cntg instances with their own data and random engine — ideal for embedding inside other generators.countrygen.hpp is the library released here. Keep core.hpp and the core/ directory (dasmig-core) in the same directory. Add
to the files you want to use it in, and supply the resources folder (or define DASMIG_COUNTRY_EMBED).
country_request{} selects from all loaded countries with population weighting. get_country(request) draws a seed from the generator's internal engine; get_country(request, seed) does not advance that engine. Replay requires the same request, seed and data; the result and JSON format are unchanged.
The request-first API replaces the old no-argument, seed-only and region-taking overloads, and removes generator-level weighted(), seed() and unseed() controls. Pass {} for default options, put filtering and weighting on the request, and supply per-call seeds for deterministic sequences.
For the complete feature guide — fields, filtering, weighting, and more — see the Usage Guide.
The country data is aggregated from multiple open-data sources:
| Source | License | Contribution |
|---|---|---|
| mledoze/countries | ODbL v1.0 | ISO codes, names, area, flag, and fallbacks for REST Countries' gaps |
| REST Countries | MPL 2.0 | Coordinates, regions, capitals, languages, currencies, borders, demonyms, population, timezones, driving side, continents |
| World Bank | CC BY 4.0 | Income level classification |
| Unicode CLDR | Unicode License v3 | Share of the population that speaks each language |
| SIL ISO 639-3 | Free to use | Names of languages CLDR does not name |
The locale tables come from:
| Source | License | Contribution |
|---|---|---|
| Unicode CLDR 47 | Unicode License v3 | Locales: formats, names, week and measurement data; cash digits |
| ISO 4217 (SIX) | Published list | Currency codes and minor units |
| IANA tzdata 2026f | Public domain | Time zones and their rules |
| GeoNames | CC BY 4.0 | The population share of each zone |
| python-holidays 0.107 | MIT | Holidays, from which the rules are inferred |
Because the data is adapted from an ODbL database, the ODbL applies to it. Output generated with the library needs a notice that it uses mledoze/countries data under the ODbL. If you publish the data itself, or a database adapted from it, you must also offer that database under the ODbL (share-alike). LICENSE_DATA.txt gives the details, the locale tables' sources included. The column-by-column sources are in `doc/data.md`.
To regenerate datasets:
Tested with:
-std=c++23)-std=c++23)/std:c++latest)| Dependency | Version | Bundled | Purpose |
|---|---|---|---|
| dasmig-core | 1.4 | Yes (core.hpp, core/) | Platform-independent random engine and distributions, data layers, JSON |
| Catch2 | 3.x | Yes (amalgamated) | Unit testing |
| Library | Description |
|---|---|
| address-generator | Postal addresses with real streets by place |
| biodata-generator | Procedural human physical characteristics |
| birth-generator | Demographically plausible birthdays |
| city-generator | Weighted city selection by population |
| device-generator | Devices, browsers, user agents and IP addresses that fit together |
| email-generator | Email addresses in each country's style |
| entity-generator | ECS-based entity generation |
| interest-generator | Religion, hobbies and favourite media by country, age and sex |
| name-generator | Culturally appropriate full names |
| nickname-generator | Gamer-style nicknames |
| occupation-generator | Employment status, education and occupation by country, age and sex |
| persona-generator | Complete characters composed from the other generators |
| phone-generator | Phone numbers valid in each country's numbering plan |
| relationship-generator | Families around a person: parents, siblings, partners and children |
| trait-generator | Personality traits with conflicts, synergies and Big Five axes |
| user-generator | Complete user records: account, username, email, phone and address |
This library is released under the MIT License.