get random from list C# code example
Example 1: c# randomize a list
var shuffledcards = cards.OrderBy(a => Guid.NewGuid()).ToList();
Example 2: random from list c#
list[Random.Range(0, list.Count)];
Example 3: get random value from list c#
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]);
}
return chosenItems;
}