FastLED 3.10.8
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 635 of file algorithm.h.

635 {
636 if (first == last) {
637 return; // Empty range, nothing to shuffle
638 }
639
640 auto n = last - first;
641 for (auto i = n - 1; i > 0; --i) {
642 // Generate random index from 0 to i (inclusive)
643 auto j = g() % (i + 1);
644
645 // Swap elements at positions i and j
646 swap(*(first + i), *(first + j));
647 }
648}
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: