random from list c#
list[Random.Range(0, list.Count)];
c# randomize a list
var shuffledcards = cards.OrderBy(a => Guid.NewGuid()).ToList();
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;
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us