Itoyori  v0.0.1
random.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "ityr/common/util.hpp"
4 
5 #if __has_include(<lxm_random/lxm_random.hpp>)
6 #include <lxm_random/lxm_random.hpp>
7 namespace ityr {
8 /*
9  * @brief Default *splittable* random number generator.
10  *
11  * A *splittable* random number generator must have a member `split()` to spawn an independent
12  * child stream of random numbers. By default, Itoyori uses *LXM*, a representative splittable
13  * random number generator presented in the following paper.
14  *
15  * [Guy L. Steele Jr. and Sebastiano Vigna. "LXM: better splittable pseudorandom number generators (and almost as fast)" in ACM OOPSLA '21.](https://doi.org/10.1145/3485525)
16  *
17  * In order to use `ityr::default_random_engine`, the header file `<lxm_random/lxm_random.hpp>`
18  * must be located under the include path at compilation time.
19  * The header file for LXM can be found at [s417-lama/lxm_random](https://github.com/s417-lama/lxm_random).
20  *
21  * @see `ityr::shuffle()`
22  */
23 using default_random_engine = lxm_random::lxm_random;
24 }
25 #else
26 namespace ityr {
27 namespace internal {
28 class random_engine_dummy {
29  void report_error() { common::die("<lxm_random/lxm_random.hpp> was not loaded but a ityr::default_random_engine is used."); }
30 public:
31  using result_type = uint64_t;
32  template <typename... Args>
33  random_engine_dummy(Args&&...) { report_error(); }
34  result_type operator()() { report_error(); return {}; }
35  template <typename... Args>
36  random_engine_dummy split(Args&&...) { report_error(); return {}; }
37  constexpr static result_type min() { return 0; }
38  constexpr static result_type max() { return std::numeric_limits<result_type>::max(); }
39 };
40 }
41 using default_random_engine = internal::random_engine_dummy;
42 }
43 #endif
monoid< T, min_functor<>, highest< T > > min
Definition: reducer.hpp:101
monoid< T, max_functor<>, lowest< T > > max
Definition: reducer.hpp:104
Definition: allocator.hpp:16
internal::random_engine_dummy default_random_engine
Definition: random.hpp:41