mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-20 13:37:28 +02:00
Add a FastRandomContext::randrange and use it
This commit is contained in:
parent
16329224e7
commit
4fd2d2fc97
7 changed files with 75 additions and 2 deletions
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue