get random value from list c#
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#:
- Title
- c# main method
- Category
- C#
- Title
- formula calculating distance coordinates latitude longitude c#
- Category
- C#
- Title
- unity up arrow input
- Category
- C#
- Title
- max of array C#
- Category
- C#
- Title
- unity rb.addexplosionforce 2d
- Category
- C#
- Title
- c# byte array to bitmap
- Category
- C#
- Title
- unity try get component
- Category
- C#
- Title
- combine two arraylist c#
- Category
- C#
- Title
- how to turn 3 floats into quartenion
- Category
- C#
- Title
- round vector3 unity
- Category
- C#
- Title
- read embedded resource c# xml
- Category
- C#
- Title
- c# expression func automatically select return type
- Category
- C#
- Title
- unity quaternion identity
- Category
- C#
- Title
- convert string to number C#
- Category
- C#
- Title
- Category
- C#
- Title
- c# remove last character from string
- Category
- C#
- Title
- format float to time c#
- Category
- C#
- Title
- c# change material in code
- Category
- C#
- Title
- get normal from 3 points
- Category
- C#
- Title
- stop unity editor playing
- Category
- C#
- Title
- letter at index of string c#
- Category
- C#
- Title
- use newtonsoft json to clone object
- Category
- C#
- Title
- c# set session variable
- Category
- C#
- Title
- unity draw wire square
- Category
- C#
- Title
- c# making a folder
- Category
- C#
- Title
- c# thread sleep
- Category
- C#
- Title
- c# how to refreshyour bindingsource
- Category
- C#
- Title
- get absolute url c#
- Category
- C#
- Title
- see if two string arrays are equal c#
- Category
- C#
- Title
- how to clear console through script unity
- Category
- C#
- Title
- c# string to memorystream
- Category
- C#
- Title
- get attribute value of xml element c#
- Category
- C#
- Title
- out parameters c#
- Category
- C#
- Title
- how to close a windows form application in c#
- Category
- C#
- Title
- how to remove space between string in c#
- Category
- C#
- Title
- c# calculate difference between two dates in days
- Category
- C#
- Title
- unity delete specific text in a string
- Category
- C#
- Title
- c# linq join multiple conditions
- Category
- C#
- Title
- query into complex object using dapper
- Category
- C#
- Title
- check connection c#
- Category
- C#
- Title
- unity detect any key
- Category
- C#
- Title
- how to select time and date in datetimepicker in c#
- Category
- C#
- Title
- isGrounded script for copy
- Category
- C#
- Title
- Time delay C# unity
- Category
- C#
- Title
- c# get hwid
- Category
- C#
- Title
- c# one line set
- Category
- C#
- Title
- unity string format time
- Category
- C#
- Title
- docker ssh
- Category
- C#
- Title
- C# sprint key
- Category
- C#
- Title
- image filter
- Category
- C#
- Title
- populate combobox from array c#
- Category
- C#
- Title
- wpf restart application c#
- Category
- C#
- Title
- xamarin hide back button
- Category
- C#
- Title
- c# new dictionary linq
- Category
- C#
- Title
- .net 4.5 use tls 1.2
- Category
- C#
- Title
- input get button uibutton
- Category
- C#
- Title
- c# how to have a multiline console.writeline
- Category
- C#
- Title
- unity enable gameobject
- Category
- C#
- Title
- c# round to closest multiple
- Category
- C#
- Title
- get first and last item list c#
- Category
- C#
- Title
- get gameobject child by name
- Category
- C#
- Title
- landscape print gridcontrol devexpress
- Category
- C#
- Title
- json ignore property c#
- Category
- C#
- Title
- c# unity max
- Category
- C#
- Title
- create asp.net which send email and sms using own api
- Category
- C#
- Title
- c# list length
- Category
- C#
- Title
- c# postfix increment operator overload
- Category
- C#
- Title
- how to switch scenes in unity
- Category
- C#
- Title
- go to next itiration in foreach C#
- Category
- C#
- Title
- c# properties
- Category
- C#
- Title
- isdaylightsavingtime in c#
- Category
- C#
- Title
- .net mvc c# alert to client browswer window
- Category
- C#
- Title
- double tryparse dot comma
- Category
- C#
- Title
- delegate function c#
- Category
- C#
- Title
- unity get decimal part of float
- Category
- C#
- Title
- doest all the methos in interface need to implement c#
- Category
- C#
- Title
- : ? conditioanl statement c#
- Category
- C#
- Title
- what is a protected int c#
- Category
- C#
- Title
- c# mongodb update multiple fields
- Category
- C#
- Title
- how to add a list to observablecollection in c#
- Category
- C#
- Title
- countdownevent
- Category
- C#
- Title
- c# get enum in list
- Category
- C#
- Title
- c# regex replace
- Category
- C#
- Title
- length of a string c#
- Category
- C#
- Title
- math.pow in C# using loop
- Category
- C#
- Title
- asp.net c# write string to text file
- Category
- C#
- Title
- panel drag all form c#
- Category
- C#
- Title
- How to search for a string from readline in c#
- Category
- C#
- Title
- Failed to retrieve Firebase Instance Id
- Category
- C#
- Title
- custom player spawner mirror
- Category
- C#
- Title
- how to make a pause feautre in unity
- Category
- C#
- Title
- convert array to list Unity C#
- Category
- C#
- Title
- c# copy file
- Category
- C#
- Title
- dictionary update c#
- Category
- C#
- Title
- mouseposition unity
- Category
- C#
- Title
- O thread de chamada não pode aceder a este objecto porque existe outro thread que já o tem
- Category
- C#
- Title
- eager loading c#
- Category
- C#
- Title
- isprime c#
- Category
- C#
- Title
- c# linq to get most recent item from IList
- Category
- C#
- Title
- windows form rounded corners
- Category
- C#