get random value from list c#
/// <summary>
/// Get random values from a list and return a list of chosen items
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="passedList"></param>
/// <param name="numberToChoose"></param>
/// <returns></returns>
public List<T> GetRandomFromList<T>(List<T> passedList, int numberToChoose)
{
System.Random rnd = new System.Random();
List<T> chosenItems = new List<T>();
for (int i = 1; i <= numberToChoose; i++)
{
int index = rnd.Next(passedList.Count);
chosenItems.Add(passedList[index]);
}
//Debug.Log(chosenItems.Count);
return chosenItems;
}list[Random.Range(0, list.Count)];
Also in C#:
- sticky footer bootstrap 3
- asp textarea
- unity3d get component
- unity accessing 2d pointlight from c# script
- how to generate random numbers in c#
- how to set progress openedge driver name for odbc connection c#
- print content of array c#
- c# unhandled exception in thread
- internal c#
- c# serialize
- how to find the area of a circle
- reference to gameobject in different scene unity
- c# random number between 0 and 1
- replace double backslash with single backslash c#
- how to check if an integer is in array c#
- how to change scenes in unity
- question mark operator in c#
- unity fall damage c#
- for each property in object c#
- player script unity
- bind repeater to dictionary
- how to reference the position of a game object unity
- how to get length of okobjectresult c#