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 527 of file algorithm.h.

527 {
528 if (first == last) {
529 return; // Empty range, nothing to shuffle
530 }
531
532 auto n = last - first;
533 for (auto i = n - 1; i > 0; --i) {
534 // Generate random index from 0 to i (inclusive)
535 auto j = g() % (i + 1);
536
537 // Swap elements at positions i and j
538 swap(*(first + i), *(first + j));
539 }
540}
void swap(array< T, N > &lhs, array< T, N > &rhs) noexcept(noexcept(lhs.swap(rhs)))
Definition array.h:156

References swap().

Referenced by shuffle().

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