02.Development/C#
[C#] List, Array 셔플
Dominic.Kim
2016. 2. 4. 02:43
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | public static void ShuffleArray<T>(T[] array) { int random1; int random2; T tmp; for (int index = 0; index < array.Length; ++index) { random1 = UnityEngine.Random.Range(0, array.Length); random2 = UnityEngine.Random.Range(0, array.Length); tmp = array[random1]; array[random1] = array[random2]; array[random2] = tmp; } } public static void ShuffleList<T>(List<T> list) { int random1; int random2; T tmp; for (int index = 0; index < list.Count; ++index) { random1 = UnityEngine.Random.Range(0, list.Count); random2 = UnityEngine.Random.Range(0, list.Count); tmp = list[random1]; list[random1] = list[random2]; list[random2] = tmp; } } | cs |