How do C++ random engines, distributions, seeding, reproducibility, modulo bias, thread use, and security requirements fit together?
Show answer and explanation
An engine produces a deterministic sequence of raw pseudo-random values; a distribution maps that sequence to a requested statistical result such as a uniform integer range. Using rand() % range can introduce modulo bias, while a standard distribution implements the required probability contract. Seed once: use a fixed recorded seed for repeatable tests and an intentional entropy source when runs should differ. random_device may have implementation-specific entropy properties, and standard distribution algorithms do not promise identical cross-library sequences, so cross-platform replay needs a documented generator and mapping. Do not share a mutable engine between threads without synchronization; give each thread owned state or protect shared state. General-purpose standard engines are not cryptographic random generators, so secrets and tokens require an operating-system or cryptographic facility.
An engine produces a deterministic sequence of raw pseudo-random values; a distribution maps that sequence to a requested statistical result such as a uniform integer range. Using rand() % range can introduce modulo bias, while a standard distribution implements the required probability contract. Seed once: use a fixed recorded seed for repeatable tests and an intentional entropy source when runs should differ. random_device may have implementation-specific entropy properties, and standard distribution algorithms do not promise identical cross-library sequences, so cross-platform replay needs a documented generator and mapping. Do not share a mutable engine between threads without synchronization; give each thread owned state or protect shared state. General-purpose standard engines are not cryptographic random generators, so secrets and tokens require an operating-system or cryptographic facility.
Connect the conclusion directly to the type, lifetime, ownership, overload-resolution rule, or library contract present in the question. State implementation dependence or a violated precondition explicitly instead of merely guessing output.