.net 下如何用C#产生永不重复的10位的随机数?如“1234567891”是一个随机数

2025-05-10 20:29:58
推荐回答(1个)
回答1:

Random rd = new Random();
            string str = "";
            while (str.Length < 10) {
                int temp = rd.Next(0, 10);
                if (!str.Contains(temp+"")) {
                    str += temp;
                }
            }
            Console.WriteLine("str="+str);