* RandomNumberGenerator(seed: int) * * This class implements a XOR-shift pseudo-random number generator (RNG). It * generates the next number of a sequence by repeatedly taking the 'exclusive * or' (the ``^`` operator) of a number with a bit-shifted version of itself. * See `here `_ for more details. * * Parameters * ---------- * seed * Seed us
| 23 | * Seed used to set the initial RNG state. |
| 24 | */ |
| 25 | class RandomNumberGenerator |
| 26 | { |
| 27 | std::array<uint32_t, 4> state_; |
| 28 | |
| 29 | public: |
| 30 | typedef uint32_t result_type; |
| 31 | |
| 32 | explicit RandomNumberGenerator(uint32_t seed); |
| 33 | explicit RandomNumberGenerator(std::array<uint32_t, 4> state); |
| 34 | |
| 35 | /** |
| 36 | * @return The minimum value this pRNG can generate. |
| 37 | */ |
| 38 | static constexpr size_t min(); |
| 39 | |
| 40 | /** |
| 41 | * @return The maximum value this pRNG can generate. |
| 42 | */ |
| 43 | static constexpr size_t max(); |
| 44 | |
| 45 | /** |
| 46 | * Generates one pseudo-random integer in the range <code>[min(), max()) |
| 47 | * </code>. |
| 48 | * |
| 49 | * @return A pseudo-random integer. |
| 50 | */ |
| 51 | result_type operator()(); |
| 52 | |
| 53 | /** |
| 54 | * Generates one pseudo-random double uniformly in the range [0, 1]. |
| 55 | * |
| 56 | * @return A pseudo-random number in the range [0, 1]. |
| 57 | */ |
| 58 | double rand(); |
| 59 | |
| 60 | /** |
| 61 | * Generates one pseudo-random integer in the range <code>[0, high)</code>. |
| 62 | * |
| 63 | * @param high Upper bound on the integer to generate. |
| 64 | * @return A pseudo-random integer. |
| 65 | */ |
| 66 | template <typename T> result_type randint(T high); |
| 67 | |
| 68 | /** |
| 69 | * Randomly shuffles the elements in the given range in-place using the |
| 70 | * Fisher-Yates algorithm. |
| 71 | * |
| 72 | * @param first Iterator to the beginning of the range to shuffle. |
| 73 | * @param last Iterator to the end of the range to shuffle. |
| 74 | */ |
| 75 | template <typename RandomIt> void shuffle(RandomIt first, RandomIt last); |
| 76 | |
| 77 | /** |
| 78 | * Returns the internal RNG state. |
| 79 | */ |
| 80 | // Could be useful for debugging. |
| 81 | std::array<uint32_t, 4> const &state() const; |
| 82 | }; |
no outgoing calls