MCPcopy Create free account
hub / github.com/Kitware/VTK / ShuffleArray

Function ShuffleArray

Filters/Sources/vtkRandomHyperTreeGridSource.cxx:37–46  ·  view source on GitHub ↗

------------------------------------------------------------------------------ * Wrapping around std::shuffle to use vtkMinimalStandardRandomSequence as a custom * generator. */

Source from the content-addressed store, hash-verified

35 * generator.
36 */
37void ShuffleArray(std::vector<int>& array, vtkMinimalStandardRandomSequence* rng)
38{
39 for (size_t i = array.size() - 1; i > 0; i--)
40 {
41 double value = rng->GetValue() * static_cast<double>(array.size());
42 int index = vtkMath::Floor(value);
43 std::swap(array[i], array[static_cast<int>(index % array.size())]);
44 rng->Next();
45 }
46}
47}
48
49//------------------------------------------------------------------------------

Callers 5

SortMethod · 0.85
SortArrayByComponentMethod · 0.85
SortMethod · 0.85
RequestDataMethod · 0.85
GenerateMaskMethod · 0.85

Calls 4

swapFunction · 0.50
sizeMethod · 0.45
GetValueMethod · 0.45
NextMethod · 0.45

Tested by

no test coverage detected