用c# 怎样实现在字符串中随机抽取10个不重复的字符

解决方案 »

  1.   

    //97-122  65-90
    byte[] bt = new byte[10];
    Random rn = new Random();
    int t =0;
    for(int i=0;i<10;i++)
    {
    t=rn.Next(t,26); bt[i] = Convert.ToByte(t + 65);
    } label1.Text = System.Text.Encoding.ASCII.GetString(bt);
      

  2.   

    copico(一路向北)的算法可能会有重复,需要加条件判断
      

  3.   

    string str = "用c# 怎样实现在字符串中随机抽取10个不重复的字符";            Random rd = new Random();            List<Char> newChar = new List<char>();
                List<int> ln = new List<int>();            int cnt = 0,
                    rnum =0;
                while(true)
                {
                    if(cnt>=10) break;
                    rnum = rd.Next(0, str.Length - 1);
                    int l=0;
                    for (; l < ln.Count; l++)
                    {
                        if (ln[l] == rnum) break;
                    }
                    if (l < ln.Count) continue;
                    else
                    {
                        newChar.Add(str[rnum]);
                        ln.Add(rnum);
                        cnt++;
                    }
                }
                return newChar.ToArray();给你代码,结贴吧!!
      

  4.   

    在顶一下拉~!
                List<Char> newChar = new List<char>();
                List<int> ln = new List<int>();
        无法表达Char和int啊