Class RngThread

Class Documentation

class RngThread

Thread-safe random number generator.

This class implements a thread-safe random number generator, based on the pcg family of random number generators. Each thread maintains a separate, private random stream, and calls to the random number generator from a given thread are automatically drawn from the correct stream.

Public Functions

inline RngThread()

Construct an RngThread.

inline RngThread(const RngType::state_type seed)

Construct an RngThread with a specified seed.

The value seed will be used for the first thread, and all subsequent threads will be seeded with values seed + 1, seed + 2, etc.

Parameters:

seed – The seed value to use

~RngThread() = default
RngThread(const RngThread&) = delete
RngThread(RngThread&&) = delete
auto operator=(const RngThread&) -> RngThread& = delete
auto operator=(RngThread&&) -> RngThread& = delete
inline void seed(const RngType::state_type seed)

Re-seed the random number generator.

The value seed will be used for the first thread, and all subsequent threads will be seeded with values seed + 1, seed + 2, etc. The result is equivalent to constructing a new RngThread using the specified seed.

Parameters:

seed – The new seed

inline auto operator()() const -> RngType&

Return the correct rng engine for the calling thread.

inline auto getState() const -> RngState

Return the serialized state of the rng engine.

As with operator(), which engine’s state is returned depends on which thread calls this method. The returned buffer can later be passed to setState() to restore the engine to exactly this state. Bytes beyond the serialized text are zeroed, so the buffer is null-terminated and safe to treat as a C string.

Returns:

A fixed-width RngState buffer holding the serialized state of the rng engine private to the calling thread

inline void setState(const RngState &state)

Set the state of the rng engine.

As with operator(), which engine’s state is set depends on which thread calls this method.

Parameters:

state – A serialized state, as returned by getState()