aboutsummaryrefslogtreecommitdiff
path: root/src/test/random_tests.cpp
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2017-02-25 12:16:58 -0800
committerPieter Wuille <pieter.wuille@gmail.com>2017-03-29 11:26:08 -0700
commit4fd2d2fc97e21efceab849576e544160fd5e3e3d (patch)
tree4d36745b0b5a72bf51b2e54bfd13151920a2c57b /src/test/random_tests.cpp
parent16329224e70d0525208f6b0ba00c5e1531a4f5ea (diff)
downloadbitcoin-4fd2d2fc97e21efceab849576e544160fd5e3e3d.tar.xz
Add a FastRandomContext::randrange and use it
Diffstat (limited to 'src/test/random_tests.cpp')
-rw-r--r--src/test/random_tests.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/test/random_tests.cpp b/src/test/random_tests.cpp
index 31b993cd38..8596734226 100644
--- a/src/test/random_tests.cpp
+++ b/src/test/random_tests.cpp
@@ -35,4 +35,19 @@ BOOST_AUTO_TEST_CASE(fastrandom_tests)
BOOST_CHECK(ctx3.rand64() != ctx4.rand64()); // extremely unlikely to be equal
}
+BOOST_AUTO_TEST_CASE(fastrandom_randbits)
+{
+ FastRandomContext ctx1;
+ FastRandomContext ctx2;
+ for (int bits = 0; bits < 63; ++bits) {
+ for (int j = 0; j < 1000; ++j) {
+ uint64_t rangebits = ctx1.randbits(bits);
+ BOOST_CHECK_EQUAL(rangebits >> bits, 0);
+ uint64_t range = ((uint64_t)1) << bits | rangebits;
+ uint64_t rand = ctx2.randrange(range);
+ BOOST_CHECK(rand < range);
+ }
+ }
+}
+
BOOST_AUTO_TEST_SUITE_END()