要发布游戏啦,平台要 3000个6位不重复的验证码 看我怎么做!!!

        static string guidList = @"D:\GuidList.txt";
        static string[] source =null;
        static  string getTheRandomYanZhengMa() {
            string result = "";
            string[] copySource = new List<string>(source).ToArray();
            Random random = new Random();
            for (int i = 0; i < 6; i++) {
                int length = copySource.Length;
                int index = random.Next(0, copySource.Length);
                
                    string temp=copySource[index];
                    result += temp;
                    copySource[index] = copySource[length - 1];
                    copySource[length - 1] = temp;
                    length--;
            }
            return result;
        }
        static void Main()
      {
          source = new string[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "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" };  
                
            using(StreamWriter st=new StreamWriter(guidList))
            {


                //[] source = {"0","1","2","3","4","5","6","7","8","9","0","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"};  
                Dictionary<string, bool> datas = new Dictionary<string, bool>();
                while (true)
                {
                    if (datas.Count == 3000)
                    {
                        break;
                    }
                    else
                    {
                        string randomText = getTheRandomYanZhengMa();
                        if (!datas.ContainsKey(randomText))
                        {
                            datas.Add(randomText,true);
                        }
                    
                    }
                
                }
                int j = 1;
                foreach (string key in datas.Keys)
                {
                    if (j == 3000)
                    {
                        st.Write((j) + "\t" + key);
                    }
                    else
                    {
                        st.Write((j ) + "\t" + key + "\n");
                    }
                    j++;
                
                }

}

posted @ 2014-02-28 21:32  夜莺_yeying  阅读(319)  评论(1编辑  收藏  举报