Get Random Items - OuterRimStudios/Utilities GitHub Wiki
CollectionUtilities.GetRandomItems
public static List<T> GetRandomItems(this List<T> list, int amount)
list The list of objects to choose from.
amount The number of items in the returned list.
List<T> Returns a randomized list of elements from the entered list.
Gets a list of random elements of a given list.
using UnityEngine;
using OuterRimStudios.Utilities;
public class ExampleClass : MonoBehaviour
{
List<string> names = new List<string>() {"Sam", "Hector", "Jeff"};
void Start()
{
List<string> randName = CollectionUtilites.GetRandomItems(names, 2); //Returns a random list of names from the list.
}
}
public static T[] GetRandomItems<T>(this T[] array, int amount)
array The array of objects to choose from. amount The number of items in the returned array.
Returns a randomized array of elements from the entered array.
Gets an array of random elements of a given array.
using UnityEngine;
using OuterRimStudios.Utilities;
public class ExampleClass : MonoBehaviour
{
string[] names = new string[] {"Sam", "Hector", "Jeff"};
void Start()
{
string[] randName = CollectionUtilites.GetRandomItems(names, 2); //Returns a random list of names from the list.
}
}