Skip to content

Instantly share code, notes, and snippets.

@oviniciusfaria
Last active October 21, 2023 12:16
Show Gist options
  • Save oviniciusfaria/acbc85d0f49af2e2d02e9de1a479e3bb to your computer and use it in GitHub Desktop.
Save oviniciusfaria/acbc85d0f49af2e2d02e9de1a479e3bb to your computer and use it in GitHub Desktop.
List Shuffle in C# Unity 3D
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