FastLED 3.9.15
Loading...
Searching...
No Matches

◆ shuffle() [2/3]

template<typename Iterator>
void fl::shuffle ( Iterator first,
Iterator last,
math::random & rng )

Definition at line 645 of file algorithm.h.

645 {
646 if (first == last) {
647 return; // Empty range, nothing to shuffle
648 }
649
650 auto n = last - first;
651 for (auto i = n - 1; i > 0; --i) {
652 // Generate random index from 0 to i (inclusive)
653 auto j = rng(static_cast<u32>(i + 1));
654
655 // Swap elements at positions i and j
656 swap(*(first + i), *(first + j));
657 }
658}
void swap(array< T, N > &lhs, array< T, N > &rhs) FL_NOEXCEPT
Definition array.h:209

References FL_NOEXCEPT, and swap().

+ Here is the call graph for this function: