<tt>xoshiro
Loading...
Searching...
No Matches
xso::xoroshiro< N, T, A, B, C >

The state for the Xoroshiro family of pseudorandom number generators. More...

#include <xoshiro.h>

Public Types

using word_type = T
 The type of the words of state.
using array_type = std::array<T, N>
 A convenience container type to hold the full state of this generator, jump polynomial coefficients, etc.

Public Member Functions

constexpr T operator[] (std::size_t i) const
 Returns the i'th state word.
template<std::output_iterator< word_type > Dst>
constexpr void get_state (Dst dst) const
 Copies the whole state into the destination iterator dst.
template<std::input_iterator Src>
requires std::convertible_to<std::iter_value_t<Src>, word_type>
constexpr void seed (Src b, Src e)
 Sets the state from an iteration of words.
constexpr void step ()
 Advance the state by one step.

Static Public Member Functions

static constexpr std::size_t word_count ()
 Class method that returns the number of words in the underlying state.
static constexpr std::size_t bit_count ()
 Class method that returns the number of bits of state.
static constexpr auto type_string ()
 Class method that returns a name for this state.
template<std::output_iterator< word_type > Dst>
static constexpr void characteristic_coefficients (Dst dst)
 Class method that fills a destination iterator with our precomputed characteristic polynomial coefficients.
static constexpr auto characteristic_coefficients ()
 Class method that returns the state's precomputed characteristic polynomial coefficients packed into an array of words.

Detailed Description

template<std::size_t N, std::unsigned_integral T, std::uint8_t A, std::uint8_t B, std::uint8_t C>
class xso::xoroshiro< N, T, A, B, C >

The state for the Xoroshiro family of pseudorandom number generators.

  • The state consists of N words of some unsigned integer type T.
  • It is advanced using the Xoshiro algorithm with parameters A, B, and C.

Member Function Documentation

◆ characteristic_coefficients() [1/2]

template<std::size_t N, std::unsigned_integral T, std::uint8_t A, std::uint8_t B, std::uint8_t C>
constexpr auto xso::xoroshiro< N, T, A, B, C >::characteristic_coefficients ( )
inlinestaticconstexpr

Class method that returns the state's precomputed characteristic polynomial coefficients packed into an array of words.

If the characteristic polynomial is \(c(x) = x^n + p(x)\) then we return an array with the coefficients of \(p(x)\) packed into words.

Panics

In practice, we have precomputed the characteristic polynomial for just a few xoshiro/xoroshiro's with specific parameters. If this State has no precomputed characteristic coefficients this method will throw an exception.

◆ characteristic_coefficients() [2/2]

template<std::size_t N, std::unsigned_integral T, std::uint8_t A, std::uint8_t B, std::uint8_t C>
template<std::output_iterator< word_type > Dst>
constexpr void xso::xoroshiro< N, T, A, B, C >::characteristic_coefficients ( Dst dst)
inlinestaticconstexpr

Class method that fills a destination iterator with our precomputed characteristic polynomial coefficients.

If the characteristic polynomial is \(c(x) = x^n + p(x)\) then we fill the destination with the coefficients of \(p(x)\) packed into words.

Panics

In practice, we have precomputed the characteristic polynomial for just a few xoshiro/xoroshiro's with specific parameters. If this State has no precomputed characteristic coefficients this method will throw an exception.

◆ get_state()

template<std::size_t N, std::unsigned_integral T, std::uint8_t A, std::uint8_t B, std::uint8_t C>
template<std::output_iterator< word_type > Dst>
void xso::xoroshiro< N, T, A, B, C >::get_state ( Dst dst) const
inlineconstexpr

Copies the whole state into the destination iterator dst.

  • The iterator's value type must be convertible from the generator's word_type.
  • The iterator must be able to accept word_count() values.

NOTE: For larger values of N we store the state as a ring buffer so we need to untangle it here.

◆ operator[]()

template<std::size_t N, std::unsigned_integral T, std::uint8_t A, std::uint8_t B, std::uint8_t C>
T xso::xoroshiro< N, T, A, B, C >::operator[] ( std::size_t i) const
inlineconstexpr

Returns the i'th state word.

NOTE: For larger values of N we store the state as a ring buffer so the indexing is a bit more complex.

◆ seed()

template<std::size_t N, std::unsigned_integral T, std::uint8_t A, std::uint8_t B, std::uint8_t C>
template<std::input_iterator Src>
requires std::convertible_to<std::iter_value_t<Src>, word_type>
void xso::xoroshiro< N, T, A, B, C >::seed ( Src b,
Src e )
inlineconstexpr

Sets the state from an iteration of words.

  • The iterator's value type must be convertible to the generator's word_type.
  • The iteration should provide word_count() values.
  • The iteration shouldn't provide all zeros as that is fixed point for all these generators.