Last active
November 8, 2024 20:27
-
-
Save oviniciusfaria/acbc85d0f49af2e2d02e9de1a479e3bb to your computer and use it in GitHub Desktop.
List Shuffle in C# Unity 3D
This file contains hidden or 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
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 = UnityEngine.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