Created
February 14, 2024 21:30
-
-
Save SiarheiPilat/81ff652cabef10bc4829b50fa73fee6b to your computer and use it in GitHub Desktop.
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
public static T[] Shuffle<T>(T[] array) | |
{ | |
T[] shuffledArray = new T[array.Length]; | |
Array.Copy(array, shuffledArray, array.Length); | |
System.Random random = new System.Random(); | |
for (int i = shuffledArray.Length - 1; i > 0; i--) | |
{ | |
int j = random.Next(0, i + 1); | |
T temp = shuffledArray[i]; | |
shuffledArray[i] = shuffledArray[j]; | |
shuffledArray[j] = temp; | |
} | |
return shuffledArray; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment