aboutsummaryrefslogtreecommitdiff
path: root/src/test/fuzz/bitset.cpp
diff options
context:
space:
mode:
authorPieter Wuille <pieter@wuille.net>2024-03-10 15:16:20 -0400
committerPieter Wuille <pieter@wuille.net>2024-07-01 10:26:46 -0400
commit6cfdc5b104caf9952393f9dac2a36539d964077f (patch)
tree1cef33e30adb25e9bef98e9eab2561d0c58f2f04 /src/test/fuzz/bitset.cpp
parent8cc2f45065fc1864f879248d1e1444588e27076b (diff)
downloadbitcoin-6cfdc5b104caf9952393f9dac2a36539d964077f.tar.xz
random: convert XoRoShiRo128PlusPlus into full RNG
Convert XoRoShiRo128PlusPlus into a full RandomMixin-based RNG class, providing all utility functionality that FastRandomContext has. In doing so, it is renamed to InsecureRandomContext, highlighting its non-cryptographic nature. To do this, a fillrand fallback is added to RandomMixin (where it is used by InsecureRandomContext), but FastRandomContext still uses its own fillrand.
Diffstat (limited to 'src/test/fuzz/bitset.cpp')
-rw-r--r--src/test/fuzz/bitset.cpp14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/test/fuzz/bitset.cpp b/src/test/fuzz/bitset.cpp
index cc3ed30f62..ce6be0499c 100644
--- a/src/test/fuzz/bitset.cpp
+++ b/src/test/fuzz/bitset.cpp
@@ -29,7 +29,7 @@ void TestType(FuzzBufferType buffer)
* bitsets and their simulations do not matter for the purpose of detecting edge cases, thus
* these are taken from a deterministically-seeded RNG instead. To provide some level of
* variation however, pick the seed based on the buffer size and size of the chosen bitset. */
- XoRoShiRo128PlusPlus rng(buffer.size() + 0x10000 * S::Size());
+ InsecureRandomContext rng(buffer.size() + 0x10000 * S::Size());
using Sim = std::bitset<S::Size()>;
// Up to 4 real BitSets (initially 2).
@@ -124,7 +124,7 @@ void TestType(FuzzBufferType buffer)
sim[dest].reset();
real[dest] = S{};
for (unsigned i = 0; i < S::Size(); ++i) {
- if (rng() & 1) {
+ if (rng.randbool()) {
sim[dest][i] = true;
real[dest].Set(i);
}
@@ -132,9 +132,9 @@ void TestType(FuzzBufferType buffer)
break;
} else if (dest < sim.size() && command-- == 0) {
/* Assign initializer list. */
- unsigned r1 = rng() % S::Size();
- unsigned r2 = rng() % S::Size();
- unsigned r3 = rng() % S::Size();
+ unsigned r1 = rng.randrange(S::Size());
+ unsigned r2 = rng.randrange(S::Size());
+ unsigned r3 = rng.randrange(S::Size());
compare_fn(dest);
sim[dest].reset();
real[dest] = {r1, r2, r3};
@@ -166,8 +166,8 @@ void TestType(FuzzBufferType buffer)
break;
} else if (sim.size() < 4 && command-- == 0) {
/* Construct with initializer list. */
- unsigned r1 = rng() % S::Size();
- unsigned r2 = rng() % S::Size();
+ unsigned r1 = rng.randrange(S::Size());
+ unsigned r2 = rng.randrange(S::Size());
sim.emplace_back();
sim.back().set(r1);
sim.back().set(r2);