Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::random_detail Namespace Reference

Functions

constexpr bool splitmix64_gives_the_numbers_of_its_reference () noexcept
 Whether SplitMix64_Rng gives, for the seeds 0 and 1234567, the first numbers of the SplittableRandom of Java and of splitmix64.c.
 
template<std::unsigned_integral Word, std::unsigned_integral Wide, class Next >
constexpr Word bounded_after_a_low_product (Next &next, const Word n, Wide product) noexcept(noexcept(next()))
 An integer in [0, n), each with the same probability, from numbers of the bits of Word: the method of Lemire.
 
template<std::unsigned_integral Word, std::unsigned_integral Wide, class Next >
constexpr Word bounded (Next &&next, const Word n) noexcept(noexcept(next()))
 An integer in [0, n), each with the same probability, from numbers of the bits of Word: the method of Lemire, which bounded_after_a_low_product() describes.
 
template<std::unsigned_integral Word, class Next >
constexpr Word masked (Next &&next, const Word n) noexcept(noexcept(next()))
 An integer in [0, n), each with the same probability, from numbers of the bits of Word, without a product of twice the bits: a number under the least mask of ones that covers n - 1, until one is below n.
 
std::uint64_t entropy_of_the_run () noexcept
 A number that changes from a run of the program to another: the time, to the precision of the clock; the processor time that the program has taken; and the address of a variable of the stack, which the system may place at random.
 
std::uint64_t seed_of_its_own () noexcept
 The seed of a Random_Source that is given none: the next number of a SplitMix64 of the process, which is seeded with entropy_of_the_run() when it gives the first one.
 

Function Documentation

◆ bounded()

template<std::unsigned_integral Word, std::unsigned_integral Wide, class Next >
constexpr Word Aleph::random_detail::bounded ( Next &&  next,
const Word  n 
)
constexprnoexcept

An integer in [0, n), each with the same probability, from numbers of the bits of Word: the method of Lemire, which bounded_after_a_low_product() describes.

Template Parameters
WordThe unsigned type of the numbers and of the integer.
WideAn unsigned type with twice the bits of Word.
Parameters
[in]nextWhat gives the numbers, uniform in the range of Word.
[in]nThe number of values.
Returns
The integer.
Precondition
n is not 0.

Definition at line 773 of file ah-random.H.

References Aleph::next(), and Aleph::product().

◆ bounded_after_a_low_product()

template<std::unsigned_integral Word, std::unsigned_integral Wide, class Next >
constexpr Word Aleph::random_detail::bounded_after_a_low_product ( Next &  next,
const Word  n,
Wide  product 
)
constexprnoexcept

An integer in [0, n), each with the same probability, from numbers of the bits of Word: the method of Lemire.

The integer is the high word of the product of a number by n. A number whose product has its low word among the first 2^w mod n values, for words of w bits, is rejected, and another one is taken: each integer is then that of as many numbers. It divides only when the low word is below n, which bounded() leaves to this function, out of line, so that its usual draw calls nothing.

Template Parameters
WordThe unsigned type of the numbers and of the integer.
WideAn unsigned type with twice the bits of Word.
Parameters
[in]nextWhat gives the numbers, uniform in the range of Word.
[in]nThe number of values.
[in]productThe product by n of the first number, whose low word is below n.
Returns
The integer.
Precondition
n is not 0.

Definition at line 748 of file ah-random.H.

References Aleph::next(), and Aleph::product().

◆ entropy_of_the_run()

std::uint64_t Aleph::random_detail::entropy_of_the_run ( )
inlinenoexcept

A number that changes from a run of the program to another: the time, to the precision of the clock; the processor time that the program has taken; and the address of a variable of the stack, which the system may place at random.

The clocks are those of the C library: <chrono> would be included by nearly every header of Aleph, through the trees, and their units would take half as long again to compile.

Definition at line 820 of file ah-random.H.

References Aleph::SplitMix64_Rng::increment, and Aleph::SplitMix64_Rng::mix().

Referenced by seed_of_its_own(), and TEST().

◆ masked()

template<std::unsigned_integral Word, class Next >
constexpr Word Aleph::random_detail::masked ( Next &&  next,
const Word  n 
)
constexprnoexcept

An integer in [0, n), each with the same probability, from numbers of the bits of Word, without a product of twice the bits: a number under the least mask of ones that covers n - 1, until one is below n.

It keeps more than half of the numbers.

Template Parameters
WordThe unsigned type of the numbers and of the integer.
Parameters
[in]nextWhat gives the numbers, uniform in the range of Word.
[in]nThe number of values.
Returns
The integer.
Precondition
n is not 0.

Definition at line 799 of file ah-random.H.

References k, and Aleph::next().

◆ seed_of_its_own()

std::uint64_t Aleph::random_detail::seed_of_its_own ( )
inlinenoexcept

The seed of a Random_Source that is given none: the next number of a SplitMix64 of the process, which is seeded with entropy_of_the_run() when it gives the first one.

Each call takes another number, from whatever thread.

Definition at line 836 of file ah-random.H.

References entropy_of_the_run(), Aleph::SplitMix64_Rng::increment, and Aleph::SplitMix64_Rng::mix().

Referenced by Aleph::Random_Source::Random_Source(), Aleph::Random_Source::operator=(), TEST(), and TEST().

◆ splitmix64_gives_the_numbers_of_its_reference()

constexpr bool Aleph::random_detail::splitmix64_gives_the_numbers_of_its_reference ( )
constexprnoexcept

Whether SplitMix64_Rng gives, for the seeds 0 and 1234567, the first numbers of the SplittableRandom of Java and of splitmix64.c.

Definition at line 715 of file ah-random.H.

References Aleph::and.