Lumiera  0.pre.03
»edit your freedom«
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
CappedGen< GEN > Class Template Reference

#include "lib/random.hpp"

Description

template<class GEN>
class lib::CappedGen< GEN >

Adapter to protect against data corruption caused by concurrent access.

Random number generators in general are not thread safe; when used from several threads concurrently, it is not a question if, but only a question when the internal state will become corrupted, leading to degraded and biased distributions of produced numbers. For some usage scenarios however, ignoring this fact and still using a single generator from several threads may be acceptable, if the quality of the distribution actually does not matter and only some diffusion of numbers is required (e.g. adding a random sleep interval). But there is a catch: whenever the value range of generated numbers is less than the total range of the used data representation, then corruption of the internal state may lead to producing numbers outside the defined range. This adapter can be used to safeguard against this scenario.

Remarks
typically using a 64bit generator on a 64bit platform is inherently safe, yet using a 32bit generator may rely on 64bit values internally, and then this problem may be triggered. See RandomConcurrent_test with the 32bit Mersenne twister as demo.

Definition at line 277 of file random.hpp.

Public Member Functions

GEN::result_type operator() ()
 
+ Inheritance diagram for CappedGen< GEN >:
+ Collaboration diagram for CappedGen< GEN >:

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