<t>Shuffle any (I)List with an extension method based on the Fisher-Yates shuffle:<br/>
<br/>
private static Random rng = new Random();<br/>
<br/>
public static void Shuffle(this IList list)<br/>
{<br/>
int n = list.Count;<br/>
while (n > 1) {<br/>
n--;<br/>
int k = rng.Next(n + 1);<br/>
T value = list[k];<br/>
list[k] = list[n];<br/>
list[n] = value;<br/>
}<br/>
}<br/>
<br/>
```<br/>
<br/>
Usage:<br/>
<br/>
```<br/>
List products = GetProducts();<br/>
products.Shuffle();<br/>
<br/>
```<br/>
<br/>
The code above uses the much criticised `System.Random` method to select swap candidates. It's fast but not as random as it should be. If you need a better quality of randomness in your shuffles, use the random number generator in `System.Security.Cryptography` like so:<br/>
<br/>
```<br/>
using System.Security.Cryptography;<br/>
...<br/>
public static void Shuffle(this IList list)<br/>
{<br/>
RNGCryptoServiceProvider provider = new RNGCryptoServiceProvider();<br/>
int n = list.Count;<br/>
while (n > 1)<br/>
{<br/>
byte[] box = new byte[1];<br/>
do provider.GetBytes(box);<br/>
while (!(box[0] < n * (Byte.MaxValue / n)));<br/>
int k = (box[0] % n);<br/>
n--;<br/>
T value = list[k];<br/>
list[k] = list[n];<br/>
list[n] = value;<br/>
}<br/>
}<br/>
<br/>
```<br/>
<br/>
A simple comparison is available [at this blog](https://web.archive.org/web/20150801085341/http://blog.thijssen.ch/2010/02/when-random-is-too-consistent.html) (WayBack Machine).<br/>
<br/>
Edit: Since writing this answer a couple years back, many people have commented or written to me, to point out the big silly flaw in my comparison. They are of course right. There's nothing wrong with `System.Random` if it's used in the way it was intended. In my first example above, I instantiate the `rng` variable inside of the `Shuffle` method, which is asking for trouble if the method is going to be called repeatedly. Below is a fixed, full example based on a really useful comment received today from @weston here on SO.<br/>
<br/>
Program.cs:<br/>
<br/>
```<br/>
using System;<br/>
using Sy<br/>
<br/>
*(Réponse tronquée)*</t>