Recently realized a truth, here to share to everyone: education represents your past, the ability to represent your present, study represents your Future.
10 years Hedong 10 years hexi, mo Bullying Juvenile Poor
Lifelong learning, Excellence
C # Shuffle algorithm is as Follows:
classprogram {Static voidMain (string[] Args) {List<string> list =Newlist<string>(); Init (list); Xipai (list); Print (list); Dipai (list); List. Clear (); } Static voidInit (list<string>List) {list. ADD ("King"); List. ADD ("Xiao Wang"); string[] color =New string[4] {"Red Peach","Black Peach","blocks","Plum Blossom" }; string[] cate =New string[] {"A","2","3","4","5","6","7","8","9","Ten","J","Q","K", }; for(inti =0; I < Color. Length; i++) { for(intj =0; J < Cate. Length; J + +) {list. ADD (color[i]+cate[j]); } } } Static voidPrint (list<string>List) { string[] card =List. ToArray (); for(inti =0; I < Card. Length; i++) {console.writeline (card[i]); } Console.readkey (); } Static voidXipai (list<string>List) { inti =List. Count; intj; if(i = =0) { return; } while(-i! =0) {Random ran=NewRandom (); J= Ran. Next ()% (i +1); stringTMP =list[i]; list[i]=list[j]; list[j]=tmp; } } Static voidDipai (list<string>List) {console.writeline ("here are the cards"); Console.WriteLine ("*************************"); for(inti =0; I <3; i++) {console.writeline (list[list. Count-1]); List. RemoveAt (list. Count-1); } } }
The Exchange position method is used, and the program executes 54 times. Efficiency is still quite high drop!
@ Chen Wolong's Blog
C # Shuffle algorithm