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