TTK
Loading...
Searching...
No Matches
Shuffle.h
Go to the documentation of this file.
1#include <cstdlib>
2#include <vector>
3
4namespace ttk {
12 template <typename T, typename U>
13 void shuffle(std::vector<T> &toShuffle, U &&rng) {
14 for(size_t i = toShuffle.size() - 1; i >= 1; i--) {
15 const auto j = rng() % i;
16 std::swap(toShuffle[i], toShuffle[j]);
17 }
18 }
19} // namespace ttk
The Topology ToolKit.
void shuffle(std::vector< T > &toShuffle, U &&rng)
Platform-independent alternative to std::shuffle implementing the Fisher-Yates shuffle algorithm.
Definition Shuffle.h:13