Skip to content

Commit 39f9a66

Browse files
dsharletgxnnpack-bot
authored andcommitted
Run Xoshiro128Plus on itself a few times to thoroughly initialize the state
This avoids non-random results for the first few uses of `operator()` PiperOrigin-RevId: 767229398
1 parent 2687503 commit 39f9a66

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

test/replicable_random_device.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ class Xoshiro128Plus {
2626
public:
2727
using result_type = uint64_t;
2828

29-
explicit Xoshiro128Plus(uint64_t s1) : state_{s1, 0} {}
29+
explicit Xoshiro128Plus(uint64_t s1) : state_{s1, 0} {
30+
// The seed might not have 64 bits of entropy, which some <random> functions
31+
// require to give good random data.
32+
for (int i = 0; i < 10; ++i) {
33+
(*this)();
34+
}
35+
}
3036

3137
uint64_t operator()() {
3238
uint64_t s1 = state_[0];

0 commit comments

Comments
 (0)