Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Unified Diff: components/variations/entropy_provider.cc

Issue 222373002: Remove use of random_shuffle() in PermutedEntropyProvider. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/variations/entropy_provider.cc
===================================================================
--- components/variations/entropy_provider.cc (revision 261125)
+++ components/variations/entropy_provider.cc (working copy)
@@ -50,7 +50,21 @@
(*mapping)[i] = static_cast<uint16>(i);
SeededRandGenerator generator(randomization_seed);
- std::random_shuffle(mapping->begin(), mapping->end(), generator);
+
+ // Do a deterministic random shuffle of the mapping using |generator|.
+ //
+ // Note: This logic is identical to the following call with libstdc++ and VS:
+ //
+ // std::random_shuffle(mapping->begin(), mapping->end(), generator);
+ //
+ // However, this is not guaranteed by the spec and some implementations (e.g.
+ // libc++) use a different algorithm. To ensure results are consistent
+ // regardless of the compiler toolchain used, use our own version.
+ for (size_t i = 1; i < mapping->size(); ++i) {
+ // Pick an element in mapping[:i+1] with which to exchange mapping[i].
+ size_t j = generator(i + 1);
+ std::swap((*mapping)[i], (*mapping)[j]);
+ }
}
} // namespace internal
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698