Answers for "random from list c#"

C#
8

random from list c#

list[Random.Range(0, list.Count)];
Posted by: Guest on March-22-2020
6

c# randomize a list

var shuffledcards = cards.OrderBy(a => Guid.NewGuid()).ToList();
Posted by: Guest on August-05-2020
-1

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;
}
Posted by: Guest on May-10-2020

C# Answers by Framework

Browse Popular Code Answers by Language