RandomIterator
random_iterator::Stream< DistibutionType, EngineType > Class Template Reference

representation for streams of pseudorandom numbers More...

#include <Stream.hpp>

Public Types

typedef EngineType engine_type
 
typedef engine_type::state_type state_type
 Engine type. More...
 
typedef engine_type::seed_type seed_type
 Type of RNG state. More...
 
typedef engine_type::advance_type advance_type
 Type of RNG seed. More...
 
typedef engine_type::init_type init_type
 Type of RNG displacement. More...
 
typedef DistibutionType distribution_type
 Type of RNG initializer. More...
 
typedef distribution_type::result_type result_type
 type of the STL compliant distribution More...
 
typedef random_iterator_tbb::transform_iterator< caller_type, counting_iterator > iterator
 type of the result More...
 

Public Member Functions

 Stream ()=delete
 type of stream iterator More...
 
 Stream (distribution_type const &distribution, seed_type seed, uint32_t stream=0)
 Constructor. More...
 
 Stream (Stream< DistibutionType, EngineType > const &other)
 Copy constructor. More...
 
iterator begin () const
 Returns an iterator to the first element of the stream. More...
 
iterator end () const
 Returns an iterator to the past last element of the stream. More...
 
result_type operator[] (advance_type n) const
 Returns the element at specified location n. More...
 
result_type operator() (void)
 At each call, this function will produce a pseudorandom number and advance the engine state. More...
 
distribution_type getDistribution () const
 Get the distribution. More...
 
void setDistribution (distribution_type dist)
 Set the distribution. More...
 
engine_type getEngine () const
 Get the associated engine. More...
 
void setEngine (engine_type engine)
 Set the object's engine. More...
 
const seed_typegetSeed () const
 Get the seed. More...
 
void setSeed (const seed_type &seed)
 Set the seed. More...
 
uint32_t getStream () const
 Get the object's stream number. More...
 
void setStream (uint32_t stream)
 Set the object's stream number. More...
 

Friends

std::ostream & operator<< (std::ostream &os, const Stream< DistibutionType, EngineType > &be)
 

Detailed Description

template<typename DistibutionType, typename EngineType>
class random_iterator::Stream< DistibutionType, EngineType >

Objects of this class represent collections of up to \( {2}^{32} \) streams of random numbers for each seed. Each of such streams has a length of \( {2}^{64} \). If the chosen distribution generates data with 64bits, like double, then each stream can handle up to 128 ExaByte of data. Stream objects are thread-safe and lazy-evaluated. Output is produced only when requested. It is user responsibility to retrieve and store, if needed, the generated output.

Template Parameters
DistibutionTypeSTL compliant distribution type. For example: std::uniform_real_distribution, std::exponential_distribution.
EngineTypeRNG type.

There are seven options:

Usage:

1) Direct class instantiation:

\\this code will print the 10 doubles randomly distributed in the range [0.0, 1.0].
\\instantiate real uniform distribution from C++ standard libray
std::uniform_real_distribution<double> udist(0.0, 1.0);
\\
Stream<std::uniform_real_distribution<double>, random_iterator::philox> uniform_stream(udist, 0x1a2b3c4d, 1 );
for( size_t i=0; i<10; ++i )
std::cout << uniform_stream[i] << std::endl;

2) Using random_iterator::make_stream(...):

\\this code will print the 10 doubles randomly distributed in the range [0.0, 1.0].
\\instantiate real uniform distribution from C++ standard libray
std::uniform_real_distribution<double> udist(0.0, 1.0);
\\instantiate the generator
random_iterator::philox rng(0x1a2b3c4d);
\\create stream
auto uniform_stream = random_iterator::make_stream(udist, rng, 1 );
for( size_t i=0; i<10; ++i )
std::cout << uniform_stream[i] << std::endl;

Definition at line 118 of file Stream.hpp.

Member Typedef Documentation

◆ advance_type

template<typename DistibutionType, typename EngineType>
typedef engine_type::advance_type random_iterator::Stream< DistibutionType, EngineType >::advance_type

Definition at line 128 of file Stream.hpp.

◆ distribution_type

template<typename DistibutionType, typename EngineType>
typedef DistibutionType random_iterator::Stream< DistibutionType, EngineType >::distribution_type

Definition at line 131 of file Stream.hpp.

◆ engine_type

template<typename DistibutionType, typename EngineType>
typedef EngineType random_iterator::Stream< DistibutionType, EngineType >::engine_type

Definition at line 125 of file Stream.hpp.

◆ init_type

template<typename DistibutionType, typename EngineType>
typedef engine_type::init_type random_iterator::Stream< DistibutionType, EngineType >::init_type

Definition at line 129 of file Stream.hpp.

◆ iterator

template<typename DistibutionType, typename EngineType>
typedef random_iterator_tbb::transform_iterator< caller_type, counting_iterator> random_iterator::Stream< DistibutionType, EngineType >::iterator

Definition at line 134 of file Stream.hpp.

◆ result_type

template<typename DistibutionType, typename EngineType>
typedef distribution_type::result_type random_iterator::Stream< DistibutionType, EngineType >::result_type

Definition at line 132 of file Stream.hpp.

◆ seed_type

template<typename DistibutionType, typename EngineType>
typedef engine_type::seed_type random_iterator::Stream< DistibutionType, EngineType >::seed_type

Definition at line 127 of file Stream.hpp.

◆ state_type

template<typename DistibutionType, typename EngineType>
typedef engine_type::state_type random_iterator::Stream< DistibutionType, EngineType >::state_type

Definition at line 126 of file Stream.hpp.

Constructor & Destructor Documentation

◆ Stream() [1/3]

template<typename DistibutionType, typename EngineType>
random_iterator::Stream< DistibutionType, EngineType >::Stream ( )
delete

◆ Stream() [2/3]

template<typename DistibutionType, typename EngineType>
random_iterator::Stream< DistibutionType, EngineType >::Stream ( distribution_type const &  distribution,
seed_type  seed,
uint32_t  stream = 0 
)
inline
Parameters
distributionDistribution with stl compliant interface.
seedSeed for pseudorandom number generation.
streamPseudorandom number stream.

Definition at line 145 of file Stream.hpp.

◆ Stream() [3/3]

template<typename DistibutionType, typename EngineType>
random_iterator::Stream< DistibutionType, EngineType >::Stream ( Stream< DistibutionType, EngineType > const &  other)
inline
Parameters
other

Definition at line 157 of file Stream.hpp.

Member Function Documentation

◆ begin()

template<typename DistibutionType, typename EngineType>
iterator random_iterator::Stream< DistibutionType, EngineType >::begin ( ) const
inline
Returns
iterator to the first element of the stream.

Definition at line 168 of file Stream.hpp.

◆ end()

template<typename DistibutionType, typename EngineType>
iterator random_iterator::Stream< DistibutionType, EngineType >::end ( ) const
inline
Returns
iterator to the past last element of the stream.

Definition at line 180 of file Stream.hpp.

◆ getDistribution()

template<typename DistibutionType, typename EngineType>
distribution_type random_iterator::Stream< DistibutionType, EngineType >::getDistribution ( ) const
inline
Returns
Copy of the object's distribution.

Definition at line 216 of file Stream.hpp.

◆ getEngine()

template<typename DistibutionType, typename EngineType>
engine_type random_iterator::Stream< DistibutionType, EngineType >::getEngine ( ) const
inline
Returns
Copy of the object's engine

Definition at line 234 of file Stream.hpp.

◆ getSeed()

template<typename DistibutionType, typename EngineType>
const seed_type& random_iterator::Stream< DistibutionType, EngineType >::getSeed ( ) const
inline
Returns
Copy of the object's seed

Definition at line 252 of file Stream.hpp.

◆ getStream()

template<typename DistibutionType, typename EngineType>
uint32_t random_iterator::Stream< DistibutionType, EngineType >::getStream ( ) const
inline
Returns
stream number

Definition at line 270 of file Stream.hpp.

◆ operator()()

template<typename DistibutionType, typename EngineType>
result_type random_iterator::Stream< DistibutionType, EngineType >::operator() ( void  )
inline
Returns
pseudorandom number distributed according with DistributionType

Definition at line 206 of file Stream.hpp.

◆ operator[]()

template<typename DistibutionType, typename EngineType>
result_type random_iterator::Stream< DistibutionType, EngineType >::operator[] ( advance_type  n) const
inline

No bounds checking is performed.

Parameters
nposition in the sequence.
Returns
element at location n

Definition at line 194 of file Stream.hpp.

◆ setDistribution()

template<typename DistibutionType, typename EngineType>
void random_iterator::Stream< DistibutionType, EngineType >::setDistribution ( distribution_type  dist)
inline
Parameters
dist

Definition at line 225 of file Stream.hpp.

◆ setEngine()

template<typename DistibutionType, typename EngineType>
void random_iterator::Stream< DistibutionType, EngineType >::setEngine ( engine_type  engine)
inline
Parameters
engine

Definition at line 243 of file Stream.hpp.

◆ setSeed()

template<typename DistibutionType, typename EngineType>
void random_iterator::Stream< DistibutionType, EngineType >::setSeed ( const seed_type seed)
inline
Parameters
seed

Definition at line 261 of file Stream.hpp.

◆ setStream()

template<typename DistibutionType, typename EngineType>
void random_iterator::Stream< DistibutionType, EngineType >::setStream ( uint32_t  stream)
inline
Parameters
stream

Definition at line 279 of file Stream.hpp.

Friends And Related Function Documentation

◆ operator<<

template<typename DistibutionType, typename EngineType>
std::ostream& operator<< ( std::ostream &  os,
const Stream< DistibutionType, EngineType > &  be 
)
friend

Definition at line 283 of file Stream.hpp.


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