List & Text Randomizer: Fisher-Yates Shuffle Algorithm & Fair Randomness
Randomize and shuffle lines of text, lists, names, and team members fairly using the unbiased Fisher-Yates (Knuth) shuffling algorithm.
Mathematical Proof: The Fisher-Yates Shuffle Algorithm ($O(N)$)
A naive shuffle using array.sort(() => Math.random() - 0.5) produces severe statistical bias because modern sorting algorithms do not perform pairwise comparisons across all elements equally.
The Fisher-Yates (Knuth) Shuffle provides a mathematically proven, unbiased permutation where every one of the $N!$ possible permutations has an identical probability of $rac{1}{N!}$:
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}Practical Workflows: Contests, Teams & Study Decks
Unbiased randomization for multiple use cases:
- Giveaways & Raffles: Pick winners with mathematical fairness.
- Team & Group Splitting: Randomly divide participants into balanced squads.
- Vocabulary Flashcards: Shuffle study decks to prevent memorizing answers based on order.
Pro Tip: Practical Application
Always use Fisher-Yates shuffling rather than simple array sorting when conducting public giveaways to ensure transparent, statistically fair outcomes.