Manual
RandomIterator is a header-only library with no dependencies. So, it is only
necessary to drop the random_iterator directory, which contains the library
source code somewhere reachable to the compiler and include the random_iterator/Stream.cpp
in the project code. All classes, functions and typedefs of the API are declared in the
namespace random_iterator.
The primary object of RandomIterator’s API is random_iterator::Stream<Distribution, Engine>. These
objects represent streams of pseudorandom numbers distributed according with the template parameter
Distribution, and generated by the algorithm speficied in Engine.
Suported Distribution
All statistical distrucions implemented in the C++ standard library are supported, as well as distrucions implemented elsewhere, following the same interface guide lines. Addicionally, the distrucions are required to be thread-safe.
Example of suported distrucions:
std::uniform_int_distributionstd::uniform_real_distributionstd::bernoulli_distributionstd::binomial_distributionstd::negative_binomial_distributionstd::geometric_distributionstd::poisson_distributionstd::exponential_distributionstd::gamma_distributionstd::weibull_distributionstd::extreme_value_distributionstd::normal_distributionstd::lognormal_distributionstd::chi_squared_distributionstd::cauchy_distributionstd::fisher_f_distributionstd::student_t_distributionstd::discrete_distributionstd::piecewise_constant_distributionstd::piecewise_linear_distribution
Detailed information on how on these distributions is available on the page Pseudo-random number generation
Supported counter-based pseudorandom number generators (CBPRNGs)
random_iterator::Stream<Distribution, Engine> class template can be instatiaded with the CBPRNGs :
ars, philox and threefry are implemented in Random123:.
squares3_128, squares4_128, random_iterator::squares3_64 and random_iterator::squares4_64 are natively implemented.
Exemplos
Sequential access
1#include <random_iterator/Stream.hpp>
2#include <random>
3
4...
5
6random_iterator::squares4_128 rng(0x548c9decbce65295);
7std::uniform_int_distribution<double> distribution(0.0, 1.0);
8
9auto stream = random_iterator::make_stream( distribution, rng, 0 );
10
11for(size_t i=0; i<10; ++i)
12 std::cout << stream() << std::endl;
Access using iterators
1#include <random_iterator/Stream.hpp>
2#include <random>
3
4...
5
6random_iterator::squares4_128 rng(0x548c9decbce65295);
7std::uniform_int_distribution<double> distribution(0.0, 1.0);
8
9auto its = random_iterator::make_stream( distribution, rng, 0 ).begin();
10
11for(size_t i=0; i<10; ++i)
12 std::cout << *(its++) << std::endl;
Access using range semantics
1#include <random_iterator/Stream.hpp>
2#include <random>
3
4...
5
6random_iterator::squares4_128 rng(0x548c9decbce65295);
7std::uniform_int_distribution<double> distribution(0.0, 1.0);
8
9auto stream = random_iterator::make_stream( distribution, rng, 0 );
10size_t i=0;
11for(auto x: stream )
12{
13 std::cout << x << std::endl;
14 if( ++i > 10) break;
15}