已经有的数据
132 33334444 张三
132 32334444 李四
132 11134444 王五 怎么从这些现有的数据 随机抽取 1 个 或者 2 个 出来。 当我在框中输入 随机抽取(2)个 就取出两个来 随机抽取(1)个 就取出一个来
132 33334444 张三
132 32334444 李四
132 11134444 王五 怎么从这些现有的数据 随机抽取 1 个 或者 2 个 出来。 当我在框中输入 随机抽取(2)个 就取出两个来 随机抽取(1)个 就取出一个来
然后 list[随机数]
List<string> list = new List<string>();
list.Add("1");
list.Add("2");
list.Add("3");
list.Add("4");
list.Add("5");
System.Random random = new Random();
return list[random.Next(list.Count)];
取出一个项后放入新的集合,放进去之前遍历新集合看是否已包含该项
{
if (list == null) throw new ArgumentNullException("sourceList");
uint i = 0;
int count = list.Count();
while(i<N)
yield return list.ElementAt(new Random().Next(count));
}