如何随机获取一个包含字母和数字的固定长度的字符串?

解决方案 »

  1.   


    string[] ch = new[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
                Random r = new Random();
                string str = string.Empty;
                for (int i = 0; i < "你要的字符串长度"; i++)
                {
                    str+=r.Next(0, 35);
                }
      

  2.   

    public static string GenerateRandomname(int len)
      {
      char[] chars = new char[]{'A','B',...};
      Random random = new Random(DateTime.Now.Millisecond);
      string name= String.Empty;
      for (int i = 0; i < len; i++)
      {
      int index = random.Next(0, 26);
      name+= chars[index];
      }
      return name;
      }
    System.Guid.NewGuid()
      

  3.   

    如何随机获取一个包含字母和数字的固定长度的字符串?(如A1,A2,B1,B2……)