//生成一个某文本中不包含的随机字符串 private static string GetRandomStr(string allStr) { int number; string resStr; do { resStr = string.Empty; Random random = new Random(); for (int i = 0; i < 9; i++) { number = random.Next(); number %= 36; if (number < 10) { number += 48; //数字0-9编码在48-57 } else { number += 55; //字母A-Z编码在65-90 } resStr += ((char)number).ToString(); } } while (allStr.Contains(resStr)); return resStr; }