MCPcopy Create free account
hub / github.com/FastLED/FastLED / shuffle

Function shuffle

src/fl/stl/algorithm.h:628–641  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

626// Shuffle function with custom random generator (Fisher-Yates shuffle)
627template <typename Iterator, typename RandomGenerator>
628void shuffle(Iterator first, Iterator last, RandomGenerator& g) FL_NOEXCEPT {
629 if (first == last) {
630 return; // Empty range, nothing to shuffle
631 }
632
633 auto n = last - first;
634 for (auto i = n - 1; i > 0; --i) {
635 // Generate random index from 0 to i (inclusive)
636 auto j = g() % (i + 1);
637
638 // Swap elements at positions i and j
639 swap(*(first + i), *(first + j));
640 }
641}
642
643// Shuffle function with fl::math::random instance
644template <typename Iterator>

Callers 2

FL_TEST_FILEFunction · 0.85
FL_TEST_FILEFunction · 0.85

Calls 1

swapFunction · 0.70

Tested by

no test coverage detected