Changeset View
Changeset View
Standalone View
Standalone View
src/test/util_tests.cpp
Show First 20 Lines • Show All 807 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(util_IsHexNumber) { | ||||
BOOST_CHECK(!IsHexNumber("x0")); // broken prefix | BOOST_CHECK(!IsHexNumber("x0")); // broken prefix | ||||
BOOST_CHECK(!IsHexNumber("0x0x00")); // two prefixes not allowed | BOOST_CHECK(!IsHexNumber("0x0x00")); // two prefixes not allowed | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(util_seed_insecure_rand) { | BOOST_AUTO_TEST_CASE(util_seed_insecure_rand) { | ||||
SeedInsecureRand(true); | SeedInsecureRand(true); | ||||
for (int mod = 2; mod < 11; mod++) { | for (int mod = 2; mod < 11; mod++) { | ||||
int mask = 1; | int mask = 1; | ||||
// Really rough binomal confidence approximation. | // Really rough binomial confidence approximation. | ||||
int err = | int err = | ||||
30 * 10000. / mod * sqrt((1. / mod * (1 - 1. / mod)) / 10000.); | 30 * 10000. / mod * sqrt((1. / mod * (1 - 1. / mod)) / 10000.); | ||||
// mask is 2^ceil(log2(mod))-1 | // mask is 2^ceil(log2(mod))-1 | ||||
while (mask < mod - 1) | while (mask < mod - 1) | ||||
mask = (mask << 1) + 1; | mask = (mask << 1) + 1; | ||||
int count = 0; | int count = 0; | ||||
// How often does it get a zero from the uniform range [0,mod)? | // How often does it get a zero from the uniform range [0,mod)? | ||||
▲ Show 20 Lines • Show All 602 Lines • Show Last 20 Lines |