Advancing the random number state via jumps

There are two functions for jumping the random number state:

template<typename T>
__host__ inline void dust::random::jump(T &state)

Jump the random number state forward by a number of steps equal to the square root of the sequence length. The xoshiro256 generators have a sequence length of 2^256 and so each of these jumps is equivalent to 2^128 steps.

Template Parameters:

T – The random number generator state type; this will be inferred based on the argument

Parameters:

state – The random number state, will be updated as a side effect

template<typename T>
__host__ inline void dust::random::long_jump(T &state)

Jump the random number state forward by a number of steps equal to the period raised to 3/4s. The xoshiro256 generators have a sequence length of 2^256 and so each of these jumps is equivalent to 2^192 steps.

Template Parameters:

T – The random number generator state type; this will be inferred based on the argument

Parameters:

state – The random number state, will be updated as a side effect

Example

#include <iostream>
#include <dust/random/random.hpp>

template <typename T>
void show_state(T& state, const char * label) {
  std::cout << label << std::endl;
  std::cout << std::hex;
  for (size_t i = 0; i < T::size(); ++i) {
    std::cout << state[i] << std::endl;
  }
}

int main() {
  using rng_state_type = dust::random::xoroshiro128plusplus;

  auto state = dust::random::seed<rng_state_type>(42);
  show_state(state, "Initial state");

  dust::random::jump(state);
  show_state(state, "\nAfter one jump");

  dust::random::long_jump(state);
  show_state(state, "\nAfter long jump");
}
Initial state
bdd732262feb6e95
57e1faba65107204

After one jump
7be6cde51a8a4905
93dc62917e1a6b74

After long jump
2902cc414b8cdb97
ba4b52663a54c408