ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::PhiloxT< W > Class Template Reference

Philox4xW-10, the counter-based std::uniform_random_bit_generator of words of \( W \) bits (32 or 64) of Salmon, Moraes, Dror and Shaw, with the sequence of std::philox4x32 and std::philox4x64 of C++26. More...

#include <ADS/numeric/RandomGenerators.h>

Public types

using result_type = W
using Block = std::array< W , 4 >
 < the type of the numbers
using Key = std::array< W , 2 >
 < a counter, or its 4 outputs

Public member functions

constexpr PhiloxT (W seed=default_seed)
 the key \( ( \mathit{seed} , 0 ) \) and the counter 0
constexpr W operator() (void)
 the next number, the next word of the buffer of two blocks, which is filled again when it is empty
constexpr void discard (unsigned long long z)
 advances by \( z \) outputs, in \( O( 1 ) \) blocks
constexpr void setCounter (const Block &c)
 the counter of the next output, which will be the first word of its block
bool operator== (const PhiloxT &) const =default
 true if the two states are equal

Static public member functions

static constexpr Block block (Block c, Key k)
 the block of the counter \( c \) under the key \( k \): 10 rounds of the products of \( 2 W \) bits by the multipliers, with the key bumped by the Weyl constants between the rounds
static constexpr W min (void)
 the least number, 0
static constexpr W max (void)
 the largest number, \( 2^W - 1 \)

Static public attributes

static constexpr W default_seed = 20111115u
 < a key

Detailed description

template<class W>
class ADS::PhiloxT< W >

Philox4xW-10, the counter-based std::uniform_random_bit_generator of words of \( W \) bits (32 or 64) of Salmon, Moraes, Dror and Shaw, with the sequence of std::philox4x32 and std::philox4x64 of C++26.

Member typedef documentation

◆ Block

template<class W>
using ADS::PhiloxT< W >::Block = std::array< W , 4 >

< the type of the numbers

◆ Key

template<class W>
using ADS::PhiloxT< W >::Key = std::array< W , 2 >

< a counter, or its 4 outputs

◆ result_type

template<class W>
using ADS::PhiloxT< W >::result_type = W

Constructor and destructor documentation

◆ PhiloxT()

template<class W>
ADS::PhiloxT< W >::PhiloxT ( W seed = default_seed)
explicitconstexpr

the key \( ( \mathit{seed} , 0 ) \) and the counter 0

Member function documentation

◆ block()

template<class W>
constexpr Block ADS::PhiloxT< W >::block ( Block c,
Key k )
staticconstexpr

the block of the counter \( c \) under the key \( k \): 10 rounds of the products of \( 2 W \) bits by the multipliers, with the key bumped by the Weyl constants between the rounds

In pseudocode (Salmon and others, beyond the book), \( M_0 , M_1 \) the multipliers and \( w_0 , w_1 \) the Weyl constants:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{block}( c , k ) \cr 2 & \quad \textbf{for}\ r \gets 0\ \textbf{to}\ 9\ \textbf{do} \cr 3 & \qquad \textbf{if}\ r > 0\ \textbf{then}\ k_0 \gets k_0 + w_0;\ k_1 \gets k_1 + w_1 \cr 4 & \qquad ( h_0 , l_0 ) \gets M_0 c_0;\ ( h_1 , l_1 ) \gets M_1 c_2 \cr 5 & \qquad c \gets ( h_1 \oplus c_1 \oplus k_0 , l_1 , h_0 \oplus c_3 \oplus k_1 , l_0 ) \cr 6 & \quad \textbf{return}\ c \end{array}} \]

◆ discard()

template<class W>
void ADS::PhiloxT< W >::discard ( unsigned long long z)
constexpr

advances by \( z \) outputs, in \( O( 1 ) \) blocks

In pseudocode (beyond the book), the counter moved instead of the blocks computed:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{discard}( z ) \cr 2 & \quad \textbf{if}\ z \le \text{the outputs left in the buffer} \ \textbf{then}\ \text{skip them};\ \textbf{return} \cr 3 & \quad z \gets z - \text{those left};\ \mathit{ctr} \gets \mathit{ctr} + \lfloor z / 4 \rfloor\quad \triangleright\ \text{on } 4 W \text{ bits} \cr 4 & \quad \text{empty the buffer, and draw } z \bmod 4 \text{ outputs} \end{array}} \]

◆ max()

template<class W>
constexpr W ADS::PhiloxT< W >::max ( void )
inlinestaticconstexpr

the largest number, \( 2^W - 1 \)

◆ min()

template<class W>
constexpr W ADS::PhiloxT< W >::min ( void )
inlinestaticconstexpr

the least number, 0

◆ operator()()

template<class W>
W ADS::PhiloxT< W >::operator() ( void )
constexpr

the next number, the next word of the buffer of two blocks, which is filled again when it is empty

◆ operator==()

template<class W>
bool ADS::PhiloxT< W >::operator== ( const PhiloxT< W > & ) const
default

true if the two states are equal

◆ setCounter()

template<class W>
void ADS::PhiloxT< W >::setCounter ( const Block & c)
constexpr

the counter of the next output, which will be the first word of its block

Member data documentation

◆ default_seed

template<class W>
W ADS::PhiloxT< W >::default_seed = 20111115u
staticconstexpr

< a key

the seed of the default constructor, as in C++26


The documentation for this class was generated from the following file: