Skip to content

Instantly share code, notes, and snippets.

@daniele-quero
Created September 4, 2023 13:57
Show Gist options
  • Save daniele-quero/dc147be6a1a17a048857c26bca6e3987 to your computer and use it in GitHub Desktop.
Save daniele-quero/dc147be6a1a17a048857c26bca6e3987 to your computer and use it in GitHub Desktop.
public class Durstenfeld<T>
{
public static void shuffle(T[] array)
{
int l = array.Length;
for (int i = l - 1; i >= 0; i--)
{
int j = Random.Range(0, i);
swap(array, i, j);
}
}
private static void swap(T[] array, int i, int j)
{
T el = array[i];
array[i] = array[j];
array[j] = el;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment