153#ifndef __ADS_RandomGenerators
154 #define __ADS_RandomGenerators
179#if defined( ADS_WITH_BOOST ) && ! defined( ADS_RANDOM_BOOST )
180 #include <boost/version.hpp>
181 #if BOOST_VERSION >= 108600
182 #define ADS_RANDOM_BOOST 1
185#ifndef ADS_RANDOM_BOOST
186 #define ADS_RANDOM_BOOST 0
189 #include <type_traits>
191 #include <boost/random/xoshiro.hpp>
200#define ADS_RNG_INLINE ADS_ALWAYS_INLINE
209 std::uniform_random_bit_generator< std::remove_reference_t< G > > &&
210 std::same_as< typename std::remove_reference_t< G >::result_type ,
212 ( std::remove_reference_t< G >::min() == 0 ) &&
213 ( std::remove_reference_t< G >::max() ==
214 std::numeric_limits< std::uint64_t >::max() );
220#if ! ADS_RANDOM_BOOST
223template<
bool StarStar >
269 static constexpr std::uint64_t
min(
void ) {
return( 0 ); }
271 static constexpr std::uint64_t
max(
void ) {
272 return( std::numeric_limits< std::uint64_t >::max() );
279 std::uint64_t f_s[ 4 ];
284template<
bool StarStar >
288 using G = std::conditional_t< StarStar , boost::random::xoshiro256mm ,
289 boost::random::xoshiro256pp >;
299 std::uint64_t
operator()(
void ) {
return( f_g() ); }
303 void jump(
void ) { f_g.jump(); }
306 static constexpr std::uint64_t
min(
void ) {
return( 0 ); }
308 static constexpr std::uint64_t
max(
void ) {
309 return( std::numeric_limits< std::uint64_t >::max() );
334 explicit constexpr WyRand( std::uint64_t seed = 1 ) : f_s( seed ) { }
352 static constexpr std::uint64_t
min(
void ) {
return( 0 ); }
354 static constexpr std::uint64_t
max(
void ) {
355 return( std::numeric_limits< std::uint64_t >::max() );
375 static_assert( std::same_as< W , std::uint32_t > ||
376 std::same_as< W , std::uint64_t > ,
377 "words of 32 or 64 bits" );
382 using Key = std::array< W , 2 >;
409 constexpr void discard(
unsigned long long z );
436 static constexpr W
min(
void ) {
return( 0 ); }
438 static constexpr W
max(
void ) {
return( std::numeric_limits< W >::max() ); }
446 static constexpr unsigned lanes = 2;
449 constexpr void refill(
void );
453 W f_buf[ 4 * lanes ] = {};
454 unsigned f_at = 4 * lanes;
494 [[nodiscard]] std::size_t
size(
void )
const {
return( f_T.size() ); }
510 template< FullWordGenerator G >
524 std::vector< Entry > f_T;
549template< FullWordGenerator G >
554template< FullWordGenerator G >
579template< FullWordGenerator G >
600template< FullWordGenerator G >
626template< std::random_access_iterator I , FullWordGenerator G >
637#include "ADS/numeric/impl/RandomGenerators.tpp"
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The arithmetic of section 17.2 and of exercises 17.1-17.3, on unsigned integers of 64 bits:
The primitives of the processor that the compilers spell each in their own way, in one form for all: ...
Hashing with random tables, beyond the book:
std::size_t size(void) const
the number of the items
Definition RandomGenerators.h:494
double probability(std::size_t i) const
the probability of , as the table gives it
std::size_t operator()(G &&g) const
an index drawn with probability proportional to its weight
AliasTable(const std::vector< double > &w)
the table of the weights , not all zero
constexpr W operator()(void)
the next number, the next word of the buffer of two blocks, which is filled again when it is empty
static constexpr std::uint32_t default_seed
Definition RandomGenerators.h:385
constexpr void discard(unsigned long long z)
advances by outputs, in blocks
static constexpr Block block(Block c, Key k)
the block of the counter under the key : 10 rounds of the products of bits by the multipliers,...
W result_type
Definition RandomGenerators.h:380
static constexpr W min(void)
the least number, 0
Definition RandomGenerators.h:436
bool operator==(const PhiloxT &) const =default
true if the two states are equal
constexpr PhiloxT(W seed=default_seed)
the key and the counter 0
std::array< W, 4 > Block
< the type of the numbers
Definition RandomGenerators.h:381
static constexpr W max(void)
the largest number,
Definition RandomGenerators.h:438
constexpr void setCounter(const Block &c)
the counter of the next output, which will be the first word of its block
std::array< W, 2 > Key
< a counter, or its 4 outputs
Definition RandomGenerators.h:382
static constexpr std::uint64_t max(void)
the largest number,
Definition RandomGenerators.h:354
bool operator==(const WyRand &) const =default
true if the two states are equal
constexpr WyRand(std::uint64_t seed=1)
< the type of the numbers
Definition RandomGenerators.h:334
static constexpr std::uint64_t min(void)
the least number, 0
Definition RandomGenerators.h:352
std::uint64_t result_type
Definition RandomGenerators.h:331
constexpr std::uint64_t operator()(void)
the next number
xoshiro256++ (or xoshiro256** if StarStar), a std::uniform_random_bit_generator of 64 bits
Definition RandomGenerators.h:225
constexpr void jump(void)
advances by steps, a stream of numbers apart
bool operator==(const Xoshiro256T &) const =default
true if the two states are equal
static constexpr std::uint64_t max(void)
the largest number,
Definition RandomGenerators.h:271
static constexpr std::uint64_t min(void)
the least number, 0
Definition RandomGenerators.h:269
std::uint64_t result_type
Definition RandomGenerators.h:227
constexpr Xoshiro256T(std::uint64_t seed=1)
< the type of the numbers
constexpr std::uint64_t operator()(void)
the next number
a std::uniform_random_bit_generator of 64 full bits, from 0 to
Definition RandomGenerators.h:208
double uniformReal(G &&g)
a double uniform in , the top 53 bits of a word times
void shuffleFast(I first, I last, G &&g)
the items of shuffled by , every permutation equally likely, the indices drawn in batches
double exponentialZiggurat(G &&g)
an exponential deviate of mean 1, by the ziggurat of Marsaglia and Tsang with 256 layers
std::uint64_t uniformBelow(G &&g, std::uint64_t s)
an integer uniform in , by the method of Lemire
double normalZiggurat(G &&g)
a normal deviate of mean 0 and variance 1, by the ziggurat of Marsaglia and Tsang with 256 layers
#define ADS_RNG_INLINE
a function inlined where it is used, so that the state of the generator stays in the registers of the...
Definition RandomGenerators.h:200
PhiloxT< std::uint64_t > Philox4x64
< Philox4x32-10
Definition RandomGenerators.h:458
Xoshiro256T< false > Xoshiro256
Definition RandomGenerators.h:320
Xoshiro256T< true > Xoshiro256StarStar
< xoshiro256++
Definition RandomGenerators.h:321
PhiloxT< std::uint32_t > Philox4x32
Definition RandomGenerators.h:457