Shuffle Elements in a List

Hi there

I want to easy shuffle the below list, so the colours element are at a different index every time the scripts get loaded:

List spaceStationColours = new List ();

spaceStationColours.Add (new SpaceStationColours (“red”));
spaceStationColours.Add (new SpaceStationColours (“green”));
spaceStationColours.Add (new SpaceStationColours (“yellow”));

Maybe I should add an integer as well 1-3 and only the integer element would change between those 3 elements, but I dont know what is the normal way to do this.

The topic How can i shuffle a list - Questions & Answers - Unity Discussions This is the classic example of what not to do!! This will produce highly biased output. See here for more information. Whats wrong about that. I got confused because there is no real answer to this.

gracias!

You can use the code from that post. The commenter is complaining that the shuffle algorithm isn’t a very good one in that it doesn’t give a perfectly random shuffle. But if you’re not able to tell how to implement Fisher-Yates from looking at the Wikipedia page, the algorithm from the UA post is more than good enough.

or just read a little further in that answer’s comments…

“Well there is no difference, now that you’ve fixed the code ;)”

This question has been asked a few times on this forum, so you can probably search and find a few different ways of shuffling a list. It is also a common c# question, so a google search can help with that as well.