Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
ah_random_test.cc
Go to the documentation of this file.
1/*
2 Aleph_w
3
4 Data structures & Algorithms
5 version 2.0.0b
6 https://github.com/lrleon/Aleph-w
7
8 This file is part of Aleph-w library
9
10 Copyright (c) 2002-2026 Leandro Rabindranath Leon
11
12 Permission is hereby granted, free of charge, to any person obtaining a copy
13 of this software and associated documentation files (the "Software"), to deal
14 in the Software without restriction, including without limitation the rights
15 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16 copies of the Software, and to permit persons to whom the Software is
17 furnished to do so, subject to the following conditions:
18
19 The above copyright notice and this permission notice shall be included in all
20 copies or substantial portions of the Software.
21
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 SOFTWARE.
29*/
30
45#include <gtest/gtest.h>
46#include <ah-random.H>
47#if ALEPH_WITH_GSL
48# include <gsl/gsl_randist.h>
49# include <gsl/gsl_rng.h>
50#endif
51
52#include <algorithm>
53#include <climits>
54#include <cmath>
55#include <cstdint>
56#include <cstring>
57#include <iomanip>
58#include <memory>
59#include <numeric>
60#include <random>
61#include <vector>
62
63using namespace Aleph;
64
65namespace
66{
67#if ALEPH_WITH_GSL
68 struct Gsl_Free
69 {
70 void operator () (gsl_rng * r) const noexcept { gsl_rng_free(r); }
71 };
72
73 // Whether the tests take the logarithm of GSL, that of the same C
74 // library: not with MSVC or clang-cl, whose programs take that of the
75 // UCRT, while the GSL of MSYS2 takes that of its own C runtime, which
76 // may differ in the last bit
77#if defined(_MSC_VER)
78 constexpr bool same_log_as_gsl = false;
79#else
80 constexpr bool same_log_as_gsl = true;
81#endif
82
83 ::testing::AssertionResult same_or_close(const double ours, const double gsl,
84 const bool exactly)
85 {
86 if (exactly ? ours == gsl
87 : std::abs(ours - gsl) <= 1e-9 * std::max(1.0, std::abs(gsl)))
88 return ::testing::AssertionSuccess();
89 return ::testing::AssertionFailure() << std::setprecision(17) << ours << " is not "
90 << gsl;
91 }
92
93 // Whether a draw of flat() or gaussian() is the one of GSL: bit by bit
94 // where GSL rounds each product, as the distributions build it for
95 // x86-64, and the logarithm of gaussian() is that of GSL; elsewhere,
96 // where GSL may fuse multiply-adds, as for arm64, or the logarithm
97 // differs, up to its last bits, which the logarithm of a Gaussian near
98 // the edge of the circle amplifies (6.6e-13 at most in the draws of
99 // these tests where GSL fuses them)
100 ::testing::AssertionResult same_real(const double ours, const double gsl,
101 const bool takes_log = false)
102 {
103#if defined(__x86_64__) || defined(_M_X64)
104 return same_or_close(ours, gsl, same_log_as_gsl or not takes_log);
105#else
106 return same_or_close(ours, gsl, false);
107#endif
108 }
109
110 // Whether a draw of exponential(), a product of its logarithm, which no
111 // multiply-add fuses, is the one of GSL: bit by bit where the
112 // logarithm is that of GSL; elsewhere, up to its last bits
113 ::testing::AssertionResult same_exponential(const double ours, const double gsl)
114 {
115 return same_or_close(ours, gsl, same_log_as_gsl);
116 }
117
118 using Gsl_Ptr = std::unique_ptr<gsl_rng, Gsl_Free>;
119
120 Gsl_Ptr make_gsl() { return Gsl_Ptr(gsl_rng_alloc(gsl_rng_mt19937)); }
121
122 // gsl_rng_mt19937, through the names of Gsl_Compatible_Rng
123 struct Gsl_Draws
124 {
125 gsl_rng * r;
126
127 unsigned long get() { return gsl_rng_get(r); }
128 unsigned long uniform_int(const unsigned long n) { return gsl_rng_uniform_int(r, n); }
129 double uniform() { return gsl_rng_uniform(r); }
130 double uniform_pos() { return gsl_rng_uniform_pos(r); }
131 };
132#endif // ALEPH_WITH_GSL
133
134 // A product rounded to double, as gaussian() and flat() round theirs
135 double rounded(const double product)
136 {
137 volatile double v = product;
138 return v;
139 }
140
141 // Seeds of every kind: 0, which GSL takes as 4357, small ones, the
142 // limits of 32 bits, and above them where unsigned long has 64 bits
143 std::vector<unsigned long> seeds()
144 {
145 std::vector<unsigned long> s = {0, 1, 2, 4357, 5489, 12345, 0x7fffffffUL,
146 0xfffffffeUL, 0xffffffffUL, 1730000000UL};
147 if constexpr (sizeof(unsigned long) > 4)
148 {
149 s.push_back(static_cast<unsigned long>(0x100000000ULL));
150 s.push_back(static_cast<unsigned long>(0x123456789abcULL));
151 s.push_back(ULONG_MAX);
152 }
153 return s;
154 }
155
156 // Bounds for uniform_int(): 1, small ones, powers of two and their
157 // neighbors, and the largest ones
158 std::vector<unsigned long> bounds()
159 {
160 std::vector<unsigned long> b = {1, 2, 3, 5, 7, 10, 100, 1000, 1023, 1024, 1025,
161 65535, 65536, 1000003, 0x7fffffffUL, 0x80000000UL,
162 0x80000001UL, 0xfffffffeUL, 0xffffffffUL};
163 return b;
164 }
165
166 // FNV-1a of 64 bits over the bytes of each number, from the lowest one,
167 // so that it is the same on every platform
168 struct Fnv1a
169 {
170 std::uint64_t value = 0xcbf29ce484222325ULL;
171
172 void add_number(const std::uint64_t x)
173 {
174 for (int i = 0; i < 8; ++i)
175 {
176 value ^= (x >> (8 * i)) & 0xff;
177 value *= 0x100000001b3ULL;
178 }
179 }
180
181 void add_real(const double x)
182 {
183 std::uint64_t bits;
184 std::memcpy(&bits, &x, sizeof bits);
185 add_number(bits);
186 }
187 };
188
189 // The hash of 20000 draws of get(), uniform_int(), uniform() and
190 // uniform_pos() from g, seeded with s, in an order that another
191 // generator picks: the draws that are the same on every platform, as
192 // those of GSL
193 template <class Rng>
194 std::uint64_t hash_of_draws(const unsigned long s, Rng && g)
195 {
196 const auto bs = bounds();
197 std::mt19937 order(static_cast<std::uint32_t>(s ^ 0x5a5a5a5aUL));
198 Fnv1a h;
199 for (int i = 0; i < 20000; ++i)
200 switch (order() % 4)
201 {
202 case 0:
203 h.add_number(g.get());
204 break;
205 case 1:
206 h.add_number(g.uniform_int(bs[order() % bs.size()]));
207 break;
208 case 2:
209 h.add_real(g.uniform());
210 break;
211 default:
212 h.add_real(g.uniform_pos());
213 break;
214 }
215 return h.value;
216 }
217}
218
219TEST(GslCompatibleRng, TheDefaultSeedIsTheOneOfGsl)
220{
222#if ALEPH_WITH_GSL
223 Gsl_Ptr r = make_gsl(); // no gsl_rng_set(): the seed 0, so 4357
224 for (int i = 0; i < 10000; ++i)
225 ASSERT_EQ(g.get(), gsl_rng_get(r.get())) << "at " << i;
226
227 EXPECT_EQ(Gsl_Compatible_Rng::min(), gsl_rng_min(r.get()));
228 EXPECT_EQ(Gsl_Compatible_Rng::max(), gsl_rng_max(r.get()));
229#else
230 // the seed 0, which GSL takes as 4357, and the range of gsl_rng_mt19937
231 EXPECT_EQ(g, Gsl_Compatible_Rng(4357));
232 EXPECT_EQ(Gsl_Compatible_Rng::min(), 0u);
233 EXPECT_EQ(Gsl_Compatible_Rng::max(), 0xffffffffu);
234#endif
235}
236
237TEST(GslCompatibleRng, TheDrawsOfGslByTheirHashes)
238{
239 // The hashes of the draws of GSL, which stand for it where it is not;
240 // where it is, they are checked against its own draws. Seeds that are
241 // the same where unsigned long has 32 bits
242 struct Golden
243 {
244 unsigned long seed;
245 std::uint64_t hash;
246 };
247 static const Golden golden[] = {
248 {0, 0x80a0475ca47c87a1ULL},
249 {1, 0x8f821e7e47e0b40bULL},
250 {4357, 0xc469a8ec8a18cd94ULL},
251 {12345, 0x6573fc224e03760dULL},
252 {0x7fffffffUL, 0x4d91b79879b89001ULL},
253 {0xffffffffUL, 0xc72e010949ebff2bULL},
254 };
255 for (const Golden & x : golden)
256 {
257 EXPECT_EQ(hash_of_draws(x.seed, Gsl_Compatible_Rng(x.seed)), x.hash)
258 << "seed " << x.seed;
259#if ALEPH_WITH_GSL
260 Gsl_Ptr r = make_gsl();
261 gsl_rng_set(r.get(), x.seed);
262 EXPECT_EQ(hash_of_draws(x.seed, Gsl_Draws{r.get()}), x.hash)
263 << "seed " << x.seed << ", of GSL";
264#endif
265 }
266}
267
268#if ALEPH_WITH_GSL
269TEST(GslCompatibleRng, EveryDrawIsTheOneOfGsl)
270{
271 Gsl_Ptr r = make_gsl();
272 const auto bs = bounds();
273 size_t draws = 0;
274 for (unsigned long s : seeds())
275 {
276 gsl_rng_set(r.get(), s);
278 std::mt19937 order(static_cast<std::uint32_t>(s ^ 0x5a5a5a5aUL));
279 for (int i = 0; i < 20000; ++i, ++draws)
280 switch (order() % 8)
281 {
282 case 0:
283 ASSERT_EQ(g(), gsl_rng_get(r.get())) << "seed " << s << " at " << i;
284 break;
285 case 1:
286 ASSERT_EQ(g.get(), gsl_rng_get(r.get())) << "seed " << s << " at " << i;
287 break;
288 case 2:
289 {
290 const unsigned long n = bs[order() % bs.size()];
291 ASSERT_EQ(g.uniform_int(n), gsl_rng_uniform_int(r.get(), n))
292 << "seed " << s << " at " << i << ", n = " << n;
293 break;
294 }
295 case 3:
296 ASSERT_EQ(g.uniform(), gsl_rng_uniform(r.get())) << "seed " << s << " at " << i;
297 break;
298 case 4:
299 ASSERT_EQ(g.uniform_pos(), gsl_rng_uniform_pos(r.get()))
300 << "seed " << s << " at " << i;
301 break;
302 case 5:
303 ASSERT_TRUE(same_real(g.flat(-3.5, 7.25), gsl_ran_flat(r.get(), -3.5, 7.25)))
304 << "seed " << s << " at " << i;
305 break;
306 case 6:
307 ASSERT_TRUE(same_real(g.gaussian(2.5), gsl_ran_gaussian(r.get(), 2.5), true))
308 << "seed " << s << " at " << i;
309 break;
310 default:
311 ASSERT_TRUE(same_exponential(g.exponential(0.75),
312 gsl_ran_exponential(r.get(), 0.75)))
313 << "seed " << s << " at " << i;
314 break;
315 }
316 }
317 EXPECT_EQ(draws, 20000 * seeds().size());
318}
319#else
320// Without GSL (ALEPH_WITH_GSL is 0), the cases that compare with it
321// report SKIPPED instead of disappearing from the run, as
322// docs/ci_sanitizer_policy.md asks of a case that a configuration
323// cannot run; TheDrawsOfGslByTheirHashes stands for GSL
324TEST(GslCompatibleRng, EveryDrawIsTheOneOfGsl)
325{
326 GTEST_SKIP() << "without GSL (ALEPH_WITH_GSL is 0)";
327}
328#endif // ALEPH_WITH_GSL
329
330TEST(GslCompatibleRng, TheRealDrawsRoundEachProduct)
331{
332 // flat() and gaussian() are the formulas of GSL with each product
333 // rounded, bit by bit, whatever the options of the build: a fused
334 // multiply-add would show here on a platform that has them
335 for (unsigned long s : seeds())
336 {
337 Gsl_Compatible_Rng g(s), twin(s);
338 for (int i = 0; i < 2000; ++i)
339 {
340 const double a = 0.1, b = 1.7; // their products are not exact
341 const double u = twin.uniform();
342 ASSERT_EQ(g.flat(a, b), rounded(a * (1 - u)) + rounded(b * u))
343 << "seed " << s << " at " << i;
344
345 double x, y, r2;
346 do
347 {
348 x = -1 + 2 * twin.uniform_pos();
349 y = -1 + 2 * twin.uniform_pos();
350 r2 = rounded(x * x) + rounded(y * y);
351 }
352 while (r2 > 1.0 or r2 == 0);
353 ASSERT_EQ(g.gaussian(2.5), 2.5 * y * std::sqrt(-2.0 * std::log(r2) / r2))
354 << "seed " << s << " at " << i;
355 }
356 EXPECT_EQ(g, twin);
357 }
358}
359
360TEST(GslCompatibleRng, SeedingAgainIsAsGslRngSet)
361{
362#if ALEPH_WITH_GSL
363 Gsl_Ptr r = make_gsl();
364#endif
365 Gsl_Compatible_Rng g(99);
366 for (unsigned long s : seeds())
367 {
368 (void) g.get(); // a state that the seed must forget
369 g.seed(s);
370 EXPECT_EQ(g, Gsl_Compatible_Rng(s)) << "seed " << s;
371#if ALEPH_WITH_GSL
372 gsl_rng_set(r.get(), s);
373 for (int i = 0; i < 1000; ++i)
374 ASSERT_EQ(g.get(), gsl_rng_get(r.get())) << "seed " << s << " at " << i;
375#endif
376 }
377
378 // 0 is 4357, and else only the low 32 bits count: 2^32 seeds with 0
379 EXPECT_EQ(Gsl_Compatible_Rng(0), Gsl_Compatible_Rng(4357));
380 if constexpr (sizeof(unsigned long) > 4)
381 {
382 EXPECT_EQ(Gsl_Compatible_Rng(static_cast<unsigned long>(0x100000005ULL)),
384 EXPECT_FALSE(Gsl_Compatible_Rng(static_cast<unsigned long>(0x100000000ULL))
385 == Gsl_Compatible_Rng(4357));
386 }
387}
388
389TEST(GslCompatibleRng, TheNumbersOfTheStandard)
390{
391 // The 10000th number of a Mersenne Twister seeded with 5489, which the
392 // standard requires of std::mt19937: the same on every platform, without
393 // GSL
394 Gsl_Compatible_Rng g(5489);
396 for (int i = 0; i < 10000; ++i)
397 x = g();
398 EXPECT_EQ(x, 4123659995u);
399}
400
401TEST(GslCompatibleRng, TheNumbersAreThoseOfStdMt19937)
402{
403 // The generator keeps the Mersenne Twister itself: its numbers are those
404 // of a std::mt19937 seeded as GSL seeds, with 4357 for 0, and else with
405 // the low 32 bits, which may be 0, through several generations of the
406 // state, and after seeding both again
407 const auto mt_seed = [] (const unsigned long x)
408 {
409 return x == 0 ? std::uint32_t(4357) : static_cast<std::uint32_t>(x & 0xffffffffUL);
410 };
411 for (const unsigned long s : seeds())
412 {
414 std::mt19937 e(mt_seed(s));
415 for (int i = 0; i < 3 * 624 + 7; ++i)
416 ASSERT_EQ(g(), e()) << "seed " << s << ", number " << i;
417 g.seed(s + 1);
418 e.seed(mt_seed(s + 1));
419 for (int i = 0; i < 700; ++i)
420 ASSERT_EQ(g(), e()) << "seed " << s << " + 1, number " << i;
421 }
422
423 // Its state is 624 words of 32 bits and the position of the next one
424 EXPECT_EQ(sizeof(Gsl_Compatible_Rng), 624 * sizeof(std::uint32_t) + sizeof(int));
425}
426
427TEST(GslCompatibleRng, UniformIntRejectsZeroAndTooLargeBounds)
428{
430 EXPECT_THROW((void) g.uniform_int(0), std::domain_error);
431 if constexpr (sizeof(unsigned long) > 4)
432 {
433 EXPECT_THROW((void) g.uniform_int(static_cast<unsigned long>(0x100000000ULL)),
434 std::domain_error);
435 }
436
437 // the largest bound is right, and 1 always gives 0
438 for (int i = 0; i < 1000; ++i)
439 {
441 EXPECT_EQ(g.uniform_int(1), 0u);
442 }
443}
444
445TEST(GslCompatibleRng, UniformIntIsItsDefinitionWhereTheQuotientReachesTheBound)
446{
447 // The quotient of a number by (2^32 - 1) / n may be n or more, and then
448 // another number is taken. With n = 92682, one number in 100000 gives n
449 // itself, and nearly as many give n + 1: in 2 million draws, both are
450 // seen some twenty times. The draws are those of the definition, from
451 // the numbers of a twin, with and without the check of n
452 const unsigned long n = 92682;
453 const unsigned long scale = 0xffffffffUL / n;
454 Gsl_Compatible_Rng checked(7), unchecked(7), twin(7);
455 size_t quotients_at_the_bound = 0, quotients_above_it = 0;
456 for (int i = 0; i < 2000000; ++i)
457 {
458 unsigned long k = twin.get() / scale;
459 while (k >= n)
460 {
461 ++(k == n ? quotients_at_the_bound : quotients_above_it);
462 k = twin.get() / scale;
463 }
464 ASSERT_EQ(checked.uniform_int(n), k) << "draw " << i;
465 ASSERT_EQ(unchecked.uniform_int_ne(n), k) << "draw " << i;
466 }
467 EXPECT_GT(quotients_at_the_bound, 5u);
468 EXPECT_GT(quotients_above_it, 5u);
469 EXPECT_EQ(checked, twin);
470 EXPECT_EQ(unchecked, twin);
471 static_assert(noexcept(unchecked.uniform_int_ne(n)) and not noexcept(checked.uniform_int(n)));
472}
473
474TEST(GslCompatibleRng, UniformIntTakesAnotherNumberAfterTheBoundInANewState)
475{
476 // The first number of a generator comes after its words are generated.
477 // With these seeds, the first ones found by trying them in order, the
478 // quotient of that number is the bound itself, 92682: the draw must
479 // take the next number, whose quotient is the one given with each seed
480 const unsigned long n = 92682;
481 const unsigned long scale = 0xffffffffUL / n;
482 struct Case
483 {
484 unsigned long seed, draw;
485 };
486 for (const Case & c : {Case{120249, 82262}, Case{131651, 64705}, Case{176754, 71349},
487 Case{194136, 85450}, Case{381252, 37245}})
488 {
489 Gsl_Compatible_Rng twin(c.seed);
490 ASSERT_EQ(twin.get() / scale, n) << "seed " << c.seed;
491 ASSERT_EQ(twin.get() / scale, c.draw) << "seed " << c.seed;
492
493 Gsl_Compatible_Rng checked(c.seed), unchecked(c.seed);
494 EXPECT_EQ(checked.uniform_int(n), c.draw) << "seed " << c.seed;
495 EXPECT_EQ(unchecked.uniform_int_ne(n), c.draw) << "seed " << c.seed;
496 EXPECT_EQ(checked, twin);
497 EXPECT_EQ(unchecked, twin);
498 }
499}
500
501TEST(GslCompatibleRng, RangesOfTheDraws)
502{
504 for (int i = 0; i < 100000; ++i)
505 {
506 const double u = g.uniform();
507 ASSERT_GE(u, 0.0);
508 ASSERT_LT(u, 1.0);
509 const double p = g.uniform_pos();
510 ASSERT_GT(p, 0.0);
511 ASSERT_LT(p, 1.0);
512 const double f = g.flat(-2.0, 3.0);
513 ASSERT_GE(f, -2.0);
514 ASSERT_LE(f, 3.0);
515 ASSERT_GE(g.exponential(1.5), 0.0);
516 ASSERT_LT(g.uniform_int(10), 10u);
517 }
518}
519
520TEST(GslCompatibleRng, MomentsOfTheDistributions)
521{
522 // the mean and the variance of 200000 draws, within a few of their
523 // standard errors
524 Gsl_Compatible_Rng g(2026);
525 const int n = 200000;
526 double s = 0, s2 = 0, e = 0, f = 0;
527 std::vector<int> counts(10, 0);
528 for (int i = 0; i < n; ++i)
529 {
530 const double x = g.gaussian(2.0);
531 s += x;
532 s2 += x * x;
533 e += g.exponential(3.0);
534 f += g.flat(1.0, 5.0);
535 ++counts[g.uniform_int(10)];
536 }
537 EXPECT_NEAR(s / n, 0.0, 0.03);
538 EXPECT_NEAR(s2 / n, 4.0, 0.05);
539 EXPECT_NEAR(e / n, 3.0, 0.03);
540 EXPECT_NEAR(f / n, 3.0, 0.02);
541 for (int c : counts)
542 EXPECT_NEAR(c, n / 10, 600);
543}
544
545TEST(GslCompatibleRng, ACopyGoesOnWithTheSameNumbers)
546{
547 Gsl_Compatible_Rng g(31);
548 for (int i = 0; i < 100; ++i)
549 (void) g();
550
551 Gsl_Compatible_Rng c = g;
552 EXPECT_EQ(c, g);
553 for (int i = 0; i < 1000; ++i)
554 ASSERT_EQ(c.uniform_int(1000), g.uniform_int(1000));
555
556 (void) c();
557 EXPECT_FALSE(c == g);
558}
559
560TEST(GslCompatibleRng, FeedsTheStandardLibrary)
561{
562 static_assert(std::uniform_random_bit_generator<Gsl_Compatible_Rng>);
563
564 std::vector<int> v(100);
565 std::iota(v.begin(), v.end(), 0);
566 Gsl_Compatible_Rng a(5), b(5);
567 auto w = v;
568 std::shuffle(v.begin(), v.end(), a);
569 std::shuffle(w.begin(), w.end(), b);
570 EXPECT_EQ(v, w);
571 EXPECT_TRUE(std::is_permutation(v.begin(), v.end(), w.begin()));
572
573 std::uniform_real_distribution<double> d(0.0, 1.0);
574 const double x = d(a);
575 EXPECT_GE(x, 0.0);
576 EXPECT_LT(x, 1.0);
577}
The random number generators of Aleph: the one that gives the numbers of the gsl_rng_mt19937 of GSL,...
long double h
Definition btreepic.C:154
long double w
Definition btreepic.C:153
size_t size_t int32_t value
Definition ca-c-api.h:116
A random number generator with the sequences of GSL's gsl_rng_mt19937.
Definition ah-random.H:147
double uniform_pos() noexcept
A real number in (0, 1), as gsl_rng_uniform_pos(r).
Definition ah-random.H:340
static constexpr result_type max() noexcept
The greatest number of operator()(): 2^32 - 1.
Definition ah-random.H:259
static constexpr result_type min() noexcept
The least number of operator()().
Definition ah-random.H:256
void seed(const unsigned long s) noexcept
Seeds again, as gsl_rng_set(r, s).
Definition ah-random.H:277
double gaussian(const double sigma) noexcept
A real number of the normal distribution of mean 0, as gsl_ran_gaussian(r, sigma).
Definition ah-random.H:375
unsigned long uniform_int(const unsigned long n)
An integer in [0, n), each with the same probability, as gsl_rng_uniform_int(r, n).
Definition ah-random.H:302
double uniform() noexcept
A real number in [0, 1), as gsl_rng_uniform(r).
Definition ah-random.H:334
double exponential(const double mu) noexcept
A real number of the exponential distribution, as gsl_ran_exponential(r, mu).
Definition ah-random.H:395
double flat(const double a, const double b) noexcept
A real number of the uniform distribution on [a, b), as gsl_ran_flat(r, a, b).
Definition ah-random.H:358
unsigned long get() noexcept
The next number, as operator()().
Definition ah-random.H:289
std::uint32_t result_type
The type of the numbers of operator()().
Definition ah-random.H:250
unsigned long uniform_int_ne(const unsigned long n) noexcept
The integer of uniform_int(), without checking n.
Definition ah-random.H:319
#define TEST(name)
__gmp_expr< typename __gmp_resolve_expr< T, V >::value_type, __gmp_binary_expr< __gmp_expr< T, U >, __gmp_expr< V, W >, __gmp_max_function > > max(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
Definition gmpfrxx.h:4188
__gmp_expr< T, __gmp_unary_expr< __gmp_expr< T, U >, __gmp_abs_function > > abs(const __gmp_expr< T, U > &expr)
Definition gmpfrxx.h:4129
static mpfr_t y
Definition mpfr_mul_d.c:3
std::size_t uniform_int(Engine &eng, const std::size_t lo, const std::size_t hi)
Sample a uniform integer in [lo, hi] (inclusive).
Definition ca-rng.H:231
Main namespace for Aleph-w library functions.
size_t size(Node *root) noexcept
See compute_cardinality_rec(Node * root).
constexpr Bit_Column bits(const unsigned n)
Column of n bits without sign: the integers of [0, 2^n - 1].
and
Check uniqueness with explicit hash + equality functors.
T product(const Container &container, const T &init=T{1})
Compute product of all elements.
STL namespace.
ValueArg< size_t > seed
Definition testHash.C:53
static int * k
Gsl_Compatible_Rng r