FastLED 3.10.10
Loading...
Searching...
No Matches

◆ shuffle() [3/3]

template<typename Iterator, typename RandomGenerator>
void fl::adl_barrier::shuffle ( Iterator first,
Iterator last,
RandomGenerator & g )

Definition at line 667 of file algorithm.h.

667 {
668 if (first == last) {
669 return; // Empty range, nothing to shuffle
670 }
671
672 auto n = last - first;
673 for (auto i = n - 1; i > 0; --i) {
674 // Generate random index from 0 to i (inclusive)
675 auto j = g() % (i + 1);
676
677 // Swap elements at positions i and j
678 swap(*(first + i), *(first + j));
679 }
680}
void swap(array< T, N > &lhs, array< T, N > &rhs) FL_NO_EXCEPT
Definition array.h:209
InputGamut g
Definition rgbw.h:125

References fl::FL_NO_EXCEPT, fl::g, and fl::swap().

Referenced by shuffle().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: