Birth Generator 1.1.1
Procedural birth date generation for C++23
Loading...
Searching...
No Matches
dasmig::bthg Class Reference

Birth generator that produces demographically plausible random birthdays using UN WPP 2024 population data. More...

#include <birthgen.hpp>

Public Member Functions

 bthg ()
 Default constructor — creates an empty generator with no data.
 
 bthg (const bthg &)=delete
 
bthgoperator= (const bthg &)=delete
 
 bthg (bthg &&) noexcept=default
 
bthgoperator= (bthg &&) noexcept=default
 
birth get_birth (std::string_view cca2)
 Generate a random birth for a specific country.
 
birth get_birth (std::string_view cca2, std::uint64_t call_seed) const
 Generate a deterministic birth for a specific country.
 
birth get_birth ()
 Generate a random birth from a random country.
 
birth get_birth (std::uint64_t call_seed) const
 Generate a deterministic birth from a random country.
 
birth get_birth (std::string_view cca2, sex bio_sex)
 Generate a random birth with a predetermined sex.
 
birth get_birth (std::string_view cca2, sex bio_sex, std::uint64_t call_seed) const
 Generate a deterministic birth with a predetermined sex.
 
birth get_birth (sex bio_sex)
 Generate a random birth from a random country with a predetermined sex.
 
birth get_birth (sex bio_sex, std::uint64_t call_seed) const
 Generate a deterministic birth from a random country with a predetermined sex.
 
birth get_birth (std::string_view cca2, year_t year)
 Generate a random birth for a specific year.
 
birth get_birth (std::string_view cca2, year_t year, std::uint64_t call_seed) const
 Generate a deterministic birth for a specific year.
 
birth get_birth (std::string_view cca2, sex bio_sex, year_t year)
 Generate a random birth with predetermined sex and year.
 
birth get_birth (std::string_view cca2, sex bio_sex, year_t year, std::uint64_t call_seed) const
 Generate a deterministic birth with predetermined sex and year.
 
birth get_birth (std::string_view cca2, age_range range)
 Generate a random birth with age within [range.min, range.max].
 
birth get_birth (std::string_view cca2, age_range range, std::uint64_t call_seed) const
 Generate a deterministic birth with age within [range.min, range.max].
 
bthgseed (std::uint64_t seed_value)
 Seed the internal random engine for deterministic sequences.
 
bthgunseed ()
 Reseed the engine with a non-deterministic source.
 
bthgweighted (bool enable)
 Set whether country selection is population-weighted.
 
bool weighted () const
 Query whether country selection is population-weighted.
 
bool has_data () const
 Check whether any data has been loaded.
 
std::size_t country_count () const
 Return the number of loaded countries.
 
void load (const std::filesystem::path &dir)
 Load birth data from a resource directory.
 
bool load (dataset tier)
 Load a specific dataset tier from auto-probed paths.
 

Static Public Member Functions

static bthginstance ()
 Access the global singleton instance.
 

Detailed Description

Birth generator that produces demographically plausible random birthdays using UN WPP 2024 population data.

The generation pipeline:

  1. Select biological sex (population M:F ratio).
  2. Select age from country-specific age pyramid.
  3. Compute birth year = current year − age.
  4. Select month from latitude-based seasonal weights.
  5. Select day within month (weekday-aware deficit).

Can be used as a singleton via instance() or constructed independently.

Thread safety
Each instance is independent. Concurrent calls to get_birth() on the same instance require external synchronisation.

Definition at line 133 of file birthgen.hpp.

Constructor & Destructor Documentation

◆ bthg()

dasmig::bthg::bthg ( )
inline

Default constructor — creates an empty generator with no data.

Definition at line 137 of file birthgen.hpp.

Member Function Documentation

◆ country_count()

std::size_t dasmig::bthg::country_count ( ) const
inline

Return the number of loaded countries.

Definition at line 367 of file birthgen.hpp.

◆ get_birth() [1/14]

birth dasmig::bthg::get_birth ( )
inline

Generate a random birth from a random country.

Exceptions
std::runtime_errorIf no data has been loaded.

Definition at line 174 of file birthgen.hpp.

◆ get_birth() [2/14]

birth dasmig::bthg::get_birth ( sex  bio_sex)
inline

Generate a random birth from a random country with a predetermined sex.

Definition at line 216 of file birthgen.hpp.

◆ get_birth() [3/14]

birth dasmig::bthg::get_birth ( sex  bio_sex,
std::uint64_t  call_seed 
) const
inline

Generate a deterministic birth from a random country with a predetermined sex.

Definition at line 236 of file birthgen.hpp.

◆ get_birth() [4/14]

birth dasmig::bthg::get_birth ( std::string_view  cca2)
inline

Generate a random birth for a specific country.

Parameters
cca2ISO 3166-1 alpha-2 country code (e.g. "US", "BR").
Exceptions
std::runtime_errorIf no data has been loaded.
std::invalid_argumentIf the country code is unknown.

Definition at line 160 of file birthgen.hpp.

◆ get_birth() [5/14]

birth dasmig::bthg::get_birth ( std::string_view  cca2,
age_range  range 
)
inline

Generate a random birth with age within [range.min, range.max].

Exceptions
std::invalid_argumentIf range.min > range.max.

Definition at line 301 of file birthgen.hpp.

◆ get_birth() [6/14]

birth dasmig::bthg::get_birth ( std::string_view  cca2,
age_range  range,
std::uint64_t  call_seed 
) const
inline

Generate a deterministic birth with age within [range.min, range.max].

Definition at line 318 of file birthgen.hpp.

◆ get_birth() [7/14]

birth dasmig::bthg::get_birth ( std::string_view  cca2,
sex  bio_sex 
)
inline

Generate a random birth with a predetermined sex.

Definition at line 200 of file birthgen.hpp.

◆ get_birth() [8/14]

birth dasmig::bthg::get_birth ( std::string_view  cca2,
sex  bio_sex,
std::uint64_t  call_seed 
) const
inline

Generate a deterministic birth with a predetermined sex.

Definition at line 207 of file birthgen.hpp.

◆ get_birth() [9/14]

birth dasmig::bthg::get_birth ( std::string_view  cca2,
sex  bio_sex,
year_t  year 
)
inline

Generate a random birth with predetermined sex and year.

Definition at line 277 of file birthgen.hpp.

◆ get_birth() [10/14]

birth dasmig::bthg::get_birth ( std::string_view  cca2,
sex  bio_sex,
year_t  year,
std::uint64_t  call_seed 
) const
inline

Generate a deterministic birth with predetermined sex and year.

Definition at line 287 of file birthgen.hpp.

◆ get_birth() [11/14]

birth dasmig::bthg::get_birth ( std::string_view  cca2,
std::uint64_t  call_seed 
) const
inline

Generate a deterministic birth for a specific country.

Definition at line 166 of file birthgen.hpp.

◆ get_birth() [12/14]

birth dasmig::bthg::get_birth ( std::string_view  cca2,
year_t  year 
)
inline

Generate a random birth for a specific year.

Parameters
cca2ISO 3166-1 alpha-2 country code.
yearBirth year (e.g. year_t{1990}). Age is derived as ref_year − year and clamped to [0, 100].

Definition at line 260 of file birthgen.hpp.

◆ get_birth() [13/14]

birth dasmig::bthg::get_birth ( std::string_view  cca2,
year_t  year,
std::uint64_t  call_seed 
) const
inline

Generate a deterministic birth for a specific year.

Definition at line 267 of file birthgen.hpp.

◆ get_birth() [14/14]

birth dasmig::bthg::get_birth ( std::uint64_t  call_seed) const
inline

Generate a deterministic birth from a random country.

Definition at line 180 of file birthgen.hpp.

◆ has_data()

bool dasmig::bthg::has_data ( ) const
inline

Check whether any data has been loaded.

Definition at line 364 of file birthgen.hpp.

◆ instance()

static bthg & dasmig::bthg::instance ( )
inlinestatic

Access the global singleton instance.

Auto-probes common resource paths on first access.

Definition at line 148 of file birthgen.hpp.

◆ load() [1/2]

void dasmig::bthg::load ( const std::filesystem::path &  dir)
inline

Load birth data from a resource directory.

Expects the directory to contain: countries.tsv, age_pyramid.tsv, monthly_births.tsv.

Definition at line 376 of file birthgen.hpp.

◆ load() [2/2]

bool dasmig::bthg::load ( dataset  tier)
inline

Load a specific dataset tier from auto-probed paths.

Definition at line 390 of file birthgen.hpp.

◆ seed()

bthg & dasmig::bthg::seed ( std::uint64_t  seed_value)
inline

Seed the internal random engine for deterministic sequences.

Definition at line 338 of file birthgen.hpp.

◆ unseed()

bthg & dasmig::bthg::unseed ( )
inline

Reseed the engine with a non-deterministic source.

Definition at line 345 of file birthgen.hpp.

◆ weighted() [1/2]

bool dasmig::bthg::weighted ( ) const
inline

Query whether country selection is population-weighted.

Definition at line 359 of file birthgen.hpp.

◆ weighted() [2/2]

bthg & dasmig::bthg::weighted ( bool  enable)
inline

Set whether country selection is population-weighted.

Definition at line 352 of file birthgen.hpp.


The documentation for this class was generated from the following file: