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

◆ shuffle() [3/3]

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

Definition at line 628 of file algorithm.h.

628 {
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}
void swap(array< T, N > &lhs, array< T, N > &rhs) FL_NOEXCEPT
Definition array.h:209

References FL_NOEXCEPT, and swap().

Referenced by shuffle().

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