What's the disadvantage of this shuffle algorithm compare to other shuffle algorithm? For example, Fisher–Yates.
Code source: http://ift.tt/1EHLr8k
private List<E> ShuffleList<E>(List<E> inputList)
{
List<E> randomList = new List<E>();
Random r = new Random();
int randomIndex = 0;
while (inputList.Count > 0)
{
randomIndex = r.Next(0, inputList.Count); //Choose a random object in the list
randomList.Add(inputList[randomIndex]); //add it to the new, random list
inputList.RemoveAt(randomIndex); //remove to avoid duplicates
}
return randomList; //return the new random list
}
Aucun commentaire:
Enregistrer un commentaire