Function utils::rng

Function Documentation

inline auto utils::rng() -> RngThread&

Return a reference to the global, thread-safe random engine.

The instance is a function-local static, so it is constructed on first use rather than before main() begins; this ensures that any exception thrown during construction (which in practice cannot happen, since the number of threads is always small) is caught here rather than escaping before main() can run. There is no reasonable way for the program to continue without a working random number generator, so a construction failure is treated as fatal: it is reported and the program exits immediately, rather than letting the exception propagate to callers that have no better way to handle it either. Being a local static in an inline function also guarantees a single, program-wide instance, rather than one per translation unit.