Skip to content

Instantly share code, notes, and snippets.

@brunomikoski
Last active August 29, 2015 13:55
Show Gist options
  • Save brunomikoski/8713008 to your computer and use it in GitHub Desktop.
Save brunomikoski/8713008 to your computer and use it in GitHub Desktop.
Shuffle List Extention
/// <summary>
/// Shuffles the element order of the specified list.
/// </summary>
public static void Shuffle<T>(this IList<T> ts) {
var count = ts.Count;
var last = count - 1;
for (var i = 0; i < last; ++i) {
var r = Random.Range(i, count);
var tmp = ts[i];
ts[i] = ts[r];
ts[r] = tmp;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment