I’m trying to write code to shuffle a list randomly by adding random elements to an empty list (and removing them as I go) until they’re all added. It seems to sort itself after 2 iterations, what’s wrong with my code?
private List<int> Shuffle(List<int> listdecreasing)
{
List<int> listfilling = new List<int>();
int leng = new int();
leng = listdecreasing.Count;
int mobileLeng = 0;
int randomholder = 0;
int foundbyrandom = 0;
for (int counter = 0 ; counter < leng ;counter++)
{
mobileLeng = listdecreasing.Count;
randomholder = UnityEngine.Random.Range(0, mobileLeng);
foundbyrandom = listdecreasing[randomholder];
listfilling.Add(foundbyrandom);
listdecreasing.RemoveAt(randomholder);
}
return listfilling;
}