![]() |
Name Generator 2.0.1
Culture-aware name generation for C++23
|
This guide covers every feature of the name-generator library in detail. For a quick overview, see the README. For the full API reference, run doxygen Doxyfile from the repository root and open doc/api/html/index.html.
dasmig/namegen.hpp and dasmig/random.hpp into your include path.resources/ folder (containing .names files) to your working directory. Choose resources/lite/ (~2 MB) for compact datasets or resources/full/ (~39 MB) for complete name lists.-std=c++23 (GCC/Clang) or /std:c++latest (MSVC).The singleton ng::instance() auto-probes resources/, ../resources/, and name-generator/resources/ on first access, preferring the lite/ subfolder, then full/, then the flat root.
Two dataset tiers are available:
| Tier | Size | Content |
|---|---|---|
dataset::lite | ~2 MB | Top-500 names per category |
dataset::full | ~39 MB | Complete name lists |
Load a specific tier:
load(dataset) probes the same base paths as the singleton and returns true if a matching directory was found.
For custom locations:
Note:
load()silently does nothing if the path does not exist or is not a directory. Always usehas_resources()to verify that databases were actually loaded.
Check whether resources loaded successfully:
105 cultures are supported:
| Culture | Code | Culture | Code | Culture | Code |
|---|---|---|---|---|---|
| Afghan | af | Filipino | ph | Moldovan | md |
| Albanian | al | Finnish | fi | Moroccan | ma |
| Algerian | dz | French | fr | Namibian | na |
| American | us | Georgian | ge | Nigerian | ng |
| Angolan | ao | German | de | Norwegian | no |
| Argentinian | ar | Ghanaian | gh | Omani | om |
| Austrian | at | Greek | gr | Palestinian | ps |
| Azerbaijani | az | Guatemalan | gt | Panamanian | pa |
| Bahraini | bh | Haitian | ht | Peruvian | pe |
| Bangladeshi | bd | Honduran | hn | Polish | pl |
| Belgian | be | Hong Konger | hk | Portuguese | pt |
| Bolivian | bo | Hungarian | hu | Puerto Rican | pr |
| Botswanan | bw | Icelandic | is | Qatari | qa |
| Brazilian | br | Indian | in | Russian | ru |
| British | gb | Indonesian | id | Salvadoran | sv |
| Bruneian | bn | Iranian | ir | Saudi | sa |
| Bulgarian | bg | Iraqi | iq | Serbian | rs |
| Burkinabe | bf | Irish | ie | Singaporean | sg |
| Burundian | bi | Israeli | il | Slovenian | si |
| Cambodian | kh | Italian | it | South African | za |
| Cameroonian | cm | Jamaican | jm | Spanish | es |
| Canadian | ca | Japanese | jp | Sudanese | sd |
| Chilean | cl | Jordanian | jo | Swedish | se |
| Chinese | cn | Kazakh | kz | Swiss | ch |
| Colombian | co | Korean | kr | Syrian | sy |
| Costa Rican | cr | Kuwaiti | kw | Taiwanese | tw |
| Croatian | hr | Lebanese | lb | Tunisian | tn |
| Cypriot | cy | Libyan | ly | Turkish | tr |
| Czech | cz | Lithuanian | lt | Turkmen | tm |
| Danish | dk | Luxembourgish | lu | Uruguayan | uy |
| Djiboutian | dj | Macanese | mo | Yemeni | ye |
| Dutch | nl | Malaysian | my | ||
| Ecuadorian | ec | Maldivian | mv | ||
| Egyptian | eg | Maltese | mt | ||
| Emirati | ae | Mauritian | mu | ||
| Estonian | ee | Mexican | mx | ||
| Ethiopian | et | ||||
| Fijian | fj |
The name return type supports chained appending:
Each ng instance is independent. The static instance() singleton uses a local static for safe initialization.
| Operation | Thread-safe? |
|---|---|
instance() | Yes (static local) |
get_name() / get_surname() on different instances | Yes |
get_name() / get_surname() on the same instance | No — requires external synchronization |
load() | No — must not be called concurrently with generation on the same instance |
For concurrent generation, give each thread its own ng instance.
A name object holds a back-pointer to the ng instance that created it. Calling append_name() or append_surname() on a name whose ng instance has been destroyed is undefined behavior. Keep the generator alive for as long as you need to chain appends:
Pass an explicit seed to produce the same name every time:
Every name records its seed. Retrieve it with name::seed():
Seed the generator engine for deterministic sequences:
Construct independent ng objects with their own name databases and random engine:
Each instance maintains its own engine:
Instances can be moved (but not copied):
| Exception | Thrown by | Condition |
|---|---|---|
std::invalid_argument | get_name() / get_surname() | No names loaded for the resolved culture/gender |
Note:
load()does not throw if the path is missing — it silently returns. Usehas_resources()to check.