The Fisher–Yates algorithm generates unbiased random permutations of a finite sequence. The running time is proportional to the number elements being shuffled.
I want to shuffle a few non-zero elements with a large number of zero elements.
Implementing the Fisher–Yates algorithm with a list would lead to the shuffling process taking too long and requiring too much storage. Most steps in the Fisher--Yates algorithm would simply switch the position of duplicate zero elements.
Does there exists a random shuffle (or alternative) algorithm that:
- Leads to unbiased permutations
- Does not require the shuffling and storing of all duplicate elements
Aucun commentaire:
Enregistrer un commentaire