using System.Collections; using System.Collections.Generic; using UnityEngine; namespace MoreMountains.Tools { /// /// Array extensions /// public static class MMArrayExtensions { /// /// Returns a random value inside the array /// /// /// /// public static T MMRandomValue(this T[] array) { int newIndex = Random.Range(0, array.Length); return array[newIndex]; } /// /// Shuffles an array /// /// /// /// public static T[] MMShuffle(this T[] array) { // Fisher Yates shuffle algorithm, see https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle for (int t = 0; t < array.Length; t++) { T tmp = array[t]; int randomIndex = Random.Range(t, array.Length); array[t] = array[randomIndex]; array[randomIndex] = tmp; } return array; } } }