C # shuffling algorithm,
I recently learned a truth, and I will share it with you here: Education represents your past, your present abilities represent your present, and learning represents your future.
Ten years in Hexi, do not bully teenagers
There is no end to learning, keep improving
C # shuffling algorithm:
Class Program {static void Main (string [] args) {List <string> list = new List <string> (); Init (list); XiPai (list ); print (list); DiPai (list); list. clear ();} static void Init (List <string> list) {list. add (""); list. add ("Tom"); string [] color = new string [4] {"Peach", "Black peach", "square", "Plum Blossom "}; string [] cate = new string [] {"A", "2", "3", "4", "5", "6", "7 ", "8", "9", "10", "J", "Q", "K",}; for (int I = 0; I <color. length; I ++) {for (int j = 0; j <cate. length; j ++) {list. add (color [I] + cate [j]) ;}} static void Print (List <string> list) {string [] card = list. toArray (); for (int I = 0; I <card. length; I ++) {Console. writeLine (card [I]);} Console. readKey ();} static void XiPai (List <string> list) {int I = list. count; int j; if (I = 0) {return;} while (-- I! = 0) {Random ran = new Random (); j = ran. next () % (I + 1); string tmp = list [I]; list [I] = list [j]; list [j] = tmp ;}} static void DiPai (List <string> list) {Console. writeLine ("bottom card"); Console. writeLine ("*************************"); for (int I = 0; I <3; I ++) {Console. writeLine (list [list. count-1]); list. removeAt (list. count-1 );}}}
The switching location method is used, and the program is executed 54 times. Efficiency is quite high!
@ Chen Wolong's blog