|
Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
|
A random number generator with the sequences of GSL's gsl_rng_mt19937.
More...
#include <ah-random.H>
Public Types | |
| using | result_type = std::uint32_t |
| The type of the numbers of operator()(). | |
Public Member Functions | |
| Gsl_Compatible_Rng () noexcept | |
A generator with the default seed, as gsl_rng_alloc(gsl_rng_mt19937). | |
| Gsl_Compatible_Rng (const unsigned long s) noexcept | |
A generator with a seed, as gsl_rng_alloc() followed by gsl_rng_set(r, s). | |
| void | seed (const unsigned long s) noexcept |
Seeds again, as gsl_rng_set(r, s). | |
| result_type | operator() () noexcept |
The next number, in [min(), max()], as gsl_rng_get(r). | |
| unsigned long | get () noexcept |
| The next number, as operator()(). | |
| unsigned long | uniform_int (const unsigned long n) |
An integer in [0, n), each with the same probability, as gsl_rng_uniform_int(r, n). | |
| unsigned long | uniform_int_ne (const unsigned long n) noexcept |
The integer of uniform_int(), without checking n. | |
| double | uniform () noexcept |
A real number in [0, 1), as gsl_rng_uniform(r). | |
| double | uniform_pos () noexcept |
A real number in (0, 1), as gsl_rng_uniform_pos(r). | |
| double | flat (const double a, const double b) noexcept |
A real number of the uniform distribution on [a, b), as gsl_ran_flat(r, a, b). | |
| double | gaussian (const double sigma) noexcept |
A real number of the normal distribution of mean 0, as gsl_ran_gaussian(r, sigma). | |
| double | exponential (const double mu) noexcept |
A real number of the exponential distribution, as gsl_ran_exponential(r, mu). | |
Static Public Member Functions | |
| static constexpr result_type | min () noexcept |
| The least number of operator()(). | |
| static constexpr result_type | max () noexcept |
| The greatest number of operator()(): 2^32 - 1. | |
Static Public Attributes | |
| static constexpr std::uint32_t | default_seed = 4357 |
| The seed of a new generator, as GSL takes 0. | |
Private Member Functions | |
| void | init (const std::uint32_t s) noexcept |
| void | generate () noexcept |
| std::uint32_t | next () noexcept |
| unsigned long | uniform_int_again (const unsigned long n, const unsigned long scale) noexcept |
Static Private Member Functions | |
| static std::uint32_t | tempered (std::uint32_t y) noexcept |
| static std::uint32_t | engine_seed (const unsigned long s) noexcept |
| static void | throw_bad_range (const unsigned long n) |
| static double | rounded (const double product) noexcept |
Private Attributes | |
| std::uint32_t | mt [state_size] |
| int | mti |
Static Private Attributes | |
| static constexpr int | state_size = 624 |
| static constexpr int | shift_size = 397 |
Friends | |
| class | Random_Source |
| bool | operator== (const Gsl_Compatible_Rng &a, const Gsl_Compatible_Rng &b) |
| Whether two generators give the same numbers from now on. | |
A random number generator with the sequences of GSL's gsl_rng_mt19937.
For each seed, the numbers and the draws are those of the functions of GSL named on each member, bit by bit, but for what the documentation of the file says of flat() and gaussian():
| Member | GSL |
|---|---|
| Gsl_Compatible_Rng(), seed(s) | gsl_rng_alloc(gsl_rng_mt19937), gsl_rng_set(r, s) |
| operator()(), get() | gsl_rng_get(r) |
| uniform_int(n) | gsl_rng_uniform_int(r, n) |
| uniform() | gsl_rng_uniform(r) |
| uniform_pos() | gsl_rng_uniform_pos(r) |
| flat(a, b) | gsl_ran_flat(r, a, b) |
| gaussian(sigma) | gsl_ran_gaussian(r, sigma) |
| exponential(mu) | gsl_ran_exponential(r, mu) |
It satisfies std::uniform_random_bit_generator, so that it can feed the distributions and algorithms of the standard library too.
The numbers come from inline code, without the call through a pointer to a function that GSL makes for each one.
Definition at line 146 of file ah-random.H.
| using Aleph::Gsl_Compatible_Rng::result_type = std::uint32_t |
The type of the numbers of operator()().
Definition at line 250 of file ah-random.H.
|
inlinenoexcept |
A generator with the default seed, as gsl_rng_alloc(gsl_rng_mt19937).
Definition at line 262 of file ah-random.H.
References default_seed, and Aleph::init.
|
inlineexplicitnoexcept |
A generator with a seed, as gsl_rng_alloc() followed by gsl_rng_set(r, s).
| [in] | s | The seed: 0 is taken as 4357, and else its low 32 bits count. |
Definition at line 270 of file ah-random.H.
References engine_seed(), and Aleph::init.
|
inlinestaticprivatenoexcept |
Definition at line 226 of file ah-random.H.
References default_seed.
Referenced by Gsl_Compatible_Rng(), and seed().
|
inlinenoexcept |
A real number of the exponential distribution, as gsl_ran_exponential(r, mu).
| [in] | mu | The mean. |
Definition at line 395 of file ah-random.H.
References uniform().
Referenced by Random_Network_Flow< Net >::connect_ranks(), TEST(), and TEST().
|
inlinenoexcept |
A real number of the uniform distribution on [a, b), as gsl_ran_flat(r, a, b).
| [in] | a | The least value. |
| [in] | b | The bound of the values. |
Definition at line 358 of file ah-random.H.
References rounded(), and uniform().
Referenced by make_random_polygon(), TEST(), and TEST().
|
inlinenoexcept |
A real number of the normal distribution of mean 0, as gsl_ran_gaussian(r, sigma).
The polar method of Box and Muller: a point of the square (-1, 1)^2, of uniform_pos(), until it falls inside the unit circle and is not its center; the squares of its coordinates are rounded before their sum.
| [in] | sigma | The standard deviation. |
Definition at line 375 of file ah-random.H.
References rounded(), uniform_pos(), and y.
Referenced by Random_Network_Flow< Net >::connect_ranks(), Random_Network_Flow< Net >::create_ranks(), and TEST().
|
inlineprivatenoexcept |
Definition at line 172 of file ah-random.H.
References k, mt, mti, shift_size, state_size, and y.
Referenced by next().
|
inlinenoexcept |
The next number, as operator()().
Definition at line 289 of file ah-random.H.
References next().
Referenced by Aleph::Bloom_Filter< T >::Bloom_Filter(), build_int_list(), build_ptr_list(), insert_n_random_items_in_map(), insert_n_random_items_in_map(), insert_n_random_items_in_set(), insert_n_random_items_in_set(), Aleph::jsw_fill_table(), main(), sample_tree(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), test(), test(), test_DynSet(), test_DynSetLinHash(), and test_hash_table().
|
inlineprivatenoexcept |
Definition at line 162 of file ah-random.H.
References mt, mti, and state_size.
Referenced by Aleph::Random_Source::mersenne_twister_of().
|
inlinestaticconstexprnoexcept |
The greatest number of operator()(): 2^32 - 1.
Definition at line 259 of file ah-random.H.
Referenced by Aleph::Bloom_Filter< T >::Bloom_Filter(), Aleph::Reservoir_Sampler< T >::Reservoir_Sampler(), Aleph::gen_random_euclidian_graph(), Aleph::DynSkipList< Key, Compare >::generator_seed(), Aleph::Gen_Interval_Tree< NodeType, T, Compare >::generator_seed(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::generator_seed(), Aleph::SkipList< Key, Type >::generator_seed(), Aleph::Gen_Treap< NodeType, Key, Compare >::generator_seed(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::generator_seed(), init_random(), Aleph::jsw_fill_table(), main(), make_random_polygon(), print_pair(), print_prio(), Aleph::Karger_Min_Cut< GT, SA >::reseed(), TEST(), TEST(), test(), throw_bad_range(), uniform_int(), and uniform_int_ne().
|
inlinestaticconstexprnoexcept |
The least number of operator()().
Definition at line 256 of file ah-random.H.
Referenced by Aleph::Reservoir_Sampler< T >::Reservoir_Sampler(), main(), and TEST().
|
inlineprivatenoexcept |
Definition at line 203 of file ah-random.H.
References generate(), mt, mti, state_size, and tempered().
Referenced by get(), operator()(), TEST_F(), TEST_F(), uniform(), uniform_int_again(), and Moved_From_Case< CsvReader >::use().
|
inlinenoexcept |
The next number, in [min(), max()], as gsl_rng_get(r).
Definition at line 283 of file ah-random.H.
References next().
|
inlinestaticprivatenoexcept |
Definition at line 242 of file ah-random.H.
References Aleph::product().
Referenced by flat(), and gaussian().
|
inlinenoexcept |
Seeds again, as gsl_rng_set(r, s).
| [in] | s | The seed: 0 is taken as 4357, and else its low 32 bits count. |
Definition at line 277 of file ah-random.H.
References engine_seed(), and Aleph::init.
Referenced by Aleph::Reservoir_Sampler< T >::clear(), init_random(), main(), Aleph::Karger_Min_Cut< GT, SA >::reseed(), TEST(), TEST(), TEST(), TYPED_TEST(), and TYPED_TEST().
|
inlinestaticprivatenoexcept |
Definition at line 193 of file ah-random.H.
References y.
Referenced by next(), and uniform_int_ne().
|
inlinestaticprivate |
Definition at line 233 of file ah-random.H.
References ah_domain_error, and max().
Referenced by uniform_int().
|
inlinenoexcept |
A real number in [0, 1), as gsl_rng_uniform(r).
Definition at line 334 of file ah-random.H.
References next().
Referenced by Aleph::Random_Digraph< GT, Init_Node, Init_Arc >::create_p(), Aleph::Random_Graph< GT, Init_Node, Init_Arc >::create_p(), exponential(), flat(), TEST(), TEST(), TEST(), and uniform_pos().
|
inline |
An integer in [0, n), each with the same probability, as gsl_rng_uniform_int(r, n).
It divides a number by (2^32 - 1) / n, and takes another one while the quotient is n or more.
| [in] | n | The number of values, in [1, max()]. |
| std::domain_error | If n is 0 or greater than max(). GSL calls its error handler, which ends the program by default. |
Definition at line 302 of file ah-random.H.
References max(), throw_bad_range(), and uniform_int_ne().
Referenced by Aleph::Random_Digraph< GT, Init_Node, Init_Arc >::balance_digraph_node(), Aleph::Random_Digraph< GT, Init_Node, Init_Arc >::balance_digraph_nodes_degree(), Aleph::Random_Graph< GT, Init_Node, Init_Arc >::balance_graph_nodes_degree(), Random_Network_Flow< Net >::connect_ranks(), Aleph::Karger_Min_Cut< GT, SA >::draw_arc(), get_rand(), Aleph::Random_Digraph< GT, Init_Node, Init_Arc >::join(), Aleph::Random_Graph< GT, Init_Node, Init_Arc >::join_random_odd_nodes(), Aleph::Random_Graph< GT, Init_Node, Init_Arc >::join_through_a_node(), main(), Aleph::Random_Digraph< GT, Init_Node, Init_Arc >::make_eulerian(), Aleph::Init_P< GT >::operator()(), Aleph::Init_Arc< GT >::operator()(), TenVectors::rand_vec(), RandTree< T >::random(), Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >::select_random_node(), Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >::select_random_node(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), test(), TEST_F(), test_hash_table(), and Aleph::Reservoir_Sampler< T >::update().
|
inlineprivatenoexcept |
Definition at line 213 of file ah-random.H.
Referenced by uniform_int_ne().
|
inlinenoexcept |
The integer of uniform_int(), without checking n.
For a caller that knows that n is in range, as a structure that draws a position among its items.
| [in] | n | The number of values. |
n is in [1, max()]: with 0 it divides by zero. Definition at line 319 of file ah-random.H.
References k, max(), mt, mti, state_size, tempered(), and uniform_int_again().
Referenced by TEST(), and uniform_int().
|
inlinenoexcept |
A real number in (0, 1), as gsl_rng_uniform_pos(r).
Definition at line 340 of file ah-random.H.
References uniform().
Referenced by gaussian(), TEST(), and TEST().
|
friend |
Whether two generators give the same numbers from now on.
| [in] | a | A generator. |
| [in] | b | Another one. |
Definition at line 406 of file ah-random.H.
|
friend |
Definition at line 159 of file ah-random.H.
|
staticconstexpr |
The seed of a new generator, as GSL takes 0.
Definition at line 253 of file ah-random.H.
Referenced by Gsl_Compatible_Rng(), engine_seed(), and Aleph::Random_Source::mersenne_word().
|
private |
Definition at line 154 of file ah-random.H.
Referenced by generate(), init(), next(), and uniform_int_ne().
|
private |
Definition at line 155 of file ah-random.H.
Referenced by generate(), init(), next(), and uniform_int_ne().
|
staticconstexprprivate |
Definition at line 152 of file ah-random.H.
Referenced by generate().
|
staticconstexprprivate |
Definition at line 151 of file ah-random.H.
Referenced by generate(), init(), next(), and uniform_int_ne().