Last active
January 3, 2018 18:48
Random shuffle
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
//пример процедуры - изменяет входящие данные | |
private void ShuffleArray(ref Card[] array) | |
{ | |
for (int i = 0; i < array.Length; i++) | |
{ | |
Card tmp = array[i]; | |
int r = Random.Range(i, array.Length); | |
array[i] = array[r]; | |
array[r] = tmp; | |
} | |
} | |
//пример функции - возвращает новую последовательность | |
private Card[] ShuffleArray(Card[] array) | |
{ | |
for (int i = 0; i < array.Length; i++) | |
{ | |
Card tmp = array[i]; | |
int r = Random.Range(i, array.Length); | |
array[i] = array[r]; | |
array[r] = tmp; | |
} | |
return array; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment