c#生成一个某文本中不包含的随机字符串

//生成一个某文本中不包含的随机字符串
        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;
        }

  

posted @ 2020-01-26 02:11  蓝点lilac  阅读(310)  评论(0编辑  收藏  举报