11 #include <boost/test/unit_test.hpp>
30 for (
int i = 10; i > 0; --i) {
39 BOOST_CHECK_EQUAL(7, ctx.rand_uniform_delay(time_point, 9s).time_since_epoch().count());
40 BOOST_CHECK_EQUAL(-6, ctx.rand_uniform_delay(time_point, -9s).time_since_epoch().count());
41 BOOST_CHECK_EQUAL(1, ctx.rand_uniform_delay(time_point, 0s).time_since_epoch().count());
42 BOOST_CHECK_EQUAL(1467825113502396065, ctx.rand_uniform_delay(time_point, 9223372036854775807s).time_since_epoch().count());
43 BOOST_CHECK_EQUAL(-970181367944767837, ctx.rand_uniform_delay(time_point, -9223372036854775807s).time_since_epoch().count());
44 BOOST_CHECK_EQUAL(24761, ctx.rand_uniform_delay(time_point, 9h).time_since_epoch().count());
60 using duration = std::chrono::microseconds;
71 for (
int i = 10; i > 0; --i) {
72 BOOST_CHECK(GetRand<uint64_t>() != uint64_t{10393729187455219830U});
95 for (
int bits = 0; bits < 63; ++bits) {
96 for (
int j = 0; j < 1000; ++j) {
97 uint64_t rangebits = ctx1.
randbits(bits);
99 uint64_t range = (uint64_t{1}) << bits | rangebits;
110 std::uniform_int_distribution<int> distribution(3, 9);
111 for (
int i = 0; i < 100; ++i) {
112 int x = distribution(ctx);
116 std::vector<int> test{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
117 std::shuffle(test.begin(), test.end(), ctx);
118 for (
int j = 1; j <= 10; ++j) {
119 BOOST_CHECK(std::find(test.begin(), test.end(), j) != test.end());
121 Shuffle(test.begin(), test.end(), ctx);
122 for (
int j = 1; j <= 10; ++j) {
123 BOOST_CHECK(std::find(test.begin(), test.end(), j) != test.end());
132 uint32_t counts[5 * 5 * 5 * 5 * 5] = {0};
133 for (
int i = 0; i < 12000; ++i) {
134 int data[5] = {0, 1, 2, 3, 4};
135 Shuffle(std::begin(data), std::end(data), ctx);
136 int pos = data[0] + data[1] * 5 + data[2] * 25 + data[3] * 125 + data[4] * 625;
139 unsigned int sum = 0;
140 double chi_score = 0.0;
141 for (
int i = 0; i < 5 * 5 * 5 * 5 * 5; ++i) {
142 int i1 = i % 5, i2 = (i / 5) % 5, i3 = (i / 25) % 5, i4 = (i / 125) % 5, i5 = i / 625;
143 uint32_t
count = counts[i];
144 if (i1 == i2 || i1 == i3 || i1 == i4 || i1 == i5 || i2 == i3 || i2 == i4 || i2 == i5 || i3 == i4 || i3 == i5 || i4 == i5) {
147 chi_score += ((
count - 100.0) * (
count - 100.0)) / 100.0;
uint32_t rand32() noexcept
Generate a random 32-bit integer.
uint64_t rand64() noexcept
Generate a random 64-bit integer.
uint256 rand256() noexcept
generate a random uint256.
uint64_t randbits(int bits) noexcept
Generate a random (bits)-bit integer.
std::vector< B > randbytes(size_t len)
Generate random bytes.
uint64_t randrange(uint64_t range) noexcept
Generate a random integer in the range [0..range).
BOOST_AUTO_TEST_SUITE_END()
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
bool g_mock_deterministic_tests
Flag to make GetRand in random.h return the same number.
bool Random_SanityCheck()
Check that OS randomness is available and returning the requested number of bytes.
constexpr auto GetRandMicros
constexpr auto GetRandMillis
void Shuffle(I first, I last, R &&rng)
More efficient than using std::shuffle on a FastRandomContext.
BOOST_AUTO_TEST_CASE(osrandom_tests)
std::chrono::time_point< std::chrono::steady_clock, std::chrono::seconds > SteadySeconds