[PATCH] D21218: [LibFuzzer] Avoid using std::random_swap() due to platform differences and implement our own version.
Mike Aizatsky via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 10 14:22:58 PDT 2016
aizatsky requested changes to this revision.
This revision now requires changes to proceed.
================
Comment at: lib/Fuzzer/FuzzerInternal.h:145
@@ +144,3 @@
+ //
+ // The algorithm used here will pick a permutation at
+ // random where every permutation has equal probability
----------------
Specify algorithm reference.
================
Comment at: lib/Fuzzer/FuzzerInternal.h:152
@@ +151,3 @@
+ N = End - First;
+ for (Offset = 0; Offset < N; ++Offset) {
+ std::swap(First[Offset], First[Offset + (*this)(N - Offset)]);
----------------
Let's see that this is literally Fisher-Yates shuffle:
https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
Even (N-2) is important to have it produce uniform shuffles.
http://reviews.llvm.org/D21218
More information about the llvm-commits
mailing list