闲得无聊之洗牌

洗牌算法只要注意到一点:余数肯定比被除数会小

这个算法我也是在网上看到的,现在弄过来。。。

调用
 string[] arra = { "A", "A", "A", "A","2","2","2","2","3","3","3","3","4","4","4","4","5","5","5","5","6","6","6","6","7","7","7","7","8","8","8","8","9","9","9","9","10","10","10","10","J","J","J","J","Q","Q","Q","Q","K","K","K","K","大王","小王" };
 get_rand_number(arra, 54);



//洗牌
        public static void get_rand_number(string[] array, int length)
        {
            int index;
            int value;
            string median;
            if (null == array || 0 == length)
                return;
            Random rd = new Random();
            /* 每次发牌的时候任意分配待交换的数据 */
            for (index = 0; index < length; index++)
            {
                int rddd = rd.Next();
                value = rddd % length;
                median = array[index];
                array[index] = array[value];
                array[value] = median;
            }

            for (int ss = 0; ss < array.Length; ss++)
            {
                Console.WriteLine(array[ss]);
            }
            Console.WriteLine("============");
            Console.ReadLine();
        }




你可能感兴趣的:(闲得无聊之洗牌)