Last active
August 29, 2015 13:55
-
-
Save brunomikoski/8713008 to your computer and use it in GitHub Desktop.
Shuffle List Extention
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <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