已经有的数据 
 132 33334444  张三
 132 32334444  李四
 132 11134444  王五    怎么从这些现有的数据 随机抽取  1  个 或者  2 个 出来。 当我在框中输入  随机抽取(2)个    就取出两个来     随机抽取(1)个    就取出一个来  

解决方案 »

  1.   

    用随机数函数 取0到数组长度的随机数 抽取几个就取几个,记得做递归 取过的就不要取了
    然后 list[随机数]  
      

  2.   

    string query="select top "+ num +" * From tb Order by newid()"
      

  3.   


                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)];
      

  4.   

    使用random随机一个数字(最大为总记录数)作为数组索引,像4楼那样
    取出一个项后放入新的集合,放进去之前遍历新集合看是否已包含该项
      

  5.   

    IEnumerable<T> GetRandomList<T>(IEnumerable<T> list, uint N)
            {
                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));
            }
      

  6.   

    distinct 加什么位置 我加了  语法错误