9#include <boost/test/unit_test.hpp>
28 for (
int i = 10; i > 0; --i) {
49 for (
int i = 10; i > 0; --i) {
50 BOOST_CHECK(
GetRand(std::numeric_limits<uint64_t>::max()) != uint64_t{10393729187455219830U});
73 for (
int bits = 0; bits < 63; ++bits) {
74 for (
int j = 0; j < 1000; ++j) {
75 uint64_t rangebits = ctx1.
randbits(bits);
77 uint64_t range = ((uint64_t)1) << bits | rangebits;
88 std::uniform_int_distribution<int> distribution(3, 9);
89 for (
int i = 0; i < 100; ++i) {
90 int x = distribution(
ctx);
94 std::vector<int> test{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
95 std::shuffle(test.begin(), test.end(),
ctx);
96 for (
int j = 1; j <= 10; ++j) {
97 BOOST_CHECK(std::find(test.begin(), test.end(), j) != test.end());
100 for (
int j = 1; j <= 10; ++j) {
101 BOOST_CHECK(std::find(test.begin(), test.end(), j) != test.end());
110 uint32_t counts[5 * 5 * 5 * 5 * 5] = {0};
111 for (
int i = 0; i < 12000; ++i) {
112 int data[5] = {0, 1, 2, 3, 4};
113 Shuffle(std::begin(data), std::end(data),
ctx);
114 int pos = data[0] + data[1] * 5 + data[2] * 25 + data[3] * 125 + data[4] * 625;
117 unsigned int sum = 0;
118 double chi_score = 0.0;
119 for (
int i = 0; i < 5 * 5 * 5 * 5 * 5; ++i) {
120 int i1 = i % 5, i2 = (i / 5) % 5, i3 = (i / 25) % 5, i4 = (i / 125) % 5, i5 = i / 625;
121 uint32_t
count = counts[i];
122 if (i1 == i2 || i1 == i3 || i1 == i4 || i1 == i5 || i2 == i3 || i2 == i4 || i2 == i5 || i3 == i4 || i3 == i5 || i4 == i5) {
125 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.
std::vector< unsigned char > randbytes(size_t len)
Generate random bytes.
uint64_t randbits(int bits) noexcept
Generate a random (bits)-bit integer.
uint64_t randrange(uint64_t range) noexcept
Generate a random integer in the range [0..range).
BOOST_AUTO_TEST_SUITE_END()
#define BOOST_FIXTURE_TEST_SUITE(a, b)
#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.
uint64_t GetRand(uint64_t nMax) noexcept
Generate a uniform random integer in the range [0..range).
int GetRandInt(int nMax) noexcept
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)
static secp256k1_context * ctx