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

◆ shuffle() [2/3]

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

Definition at line 544 of file algorithm.h.

544 {
545 if (first == last) {
546 return; // Empty range, nothing to shuffle
547 }
548
549 auto n = last - first;
550 for (auto i = n - 1; i > 0; --i) {
551 // Generate random index from 0 to i (inclusive)
552 auto j = rng(static_cast<u32>(i + 1));
553
554 // Swap elements at positions i and j
555 swap(*(first + i), *(first + j));
556 }
557}
void swap(array< T, N > &lhs, array< T, N > &rhs) noexcept(noexcept(lhs.swap(rhs)))
Definition array.h:156

References swap().

+ Here is the call graph for this function: