Capítulo 177 de 411
Two small helpers for picking random array elements: one that pulls every element exactly once before the pool "refills" and reshuffles, and one that just avoids repeating the immediately previous pick.
array.eligible, via gsap.utils.shuffle) and pops from it each call; once empty, reshuffles automatically. Guarantees every element is used before any repeats.array.selected (the previous pick), so only immediate repeats are avoided, not full-cycle uniqueness.function pluckRandomFrom(array) {
return (
array.eligible && array.eligible.length
? array.eligible
: (array.eligible = gsap.utils.shuffle(array.slice(0)))
).pop();
}
pluckRandomFrom when you need "every item shown once before repeats"; pick getRandomFrom when you only care about not repeating twice in a row.