The algorithm of this shuffle way:
1: Initialize an array of length 54, and 54 cards.
2: Starting from I=1 to 54, each time from the remaining pile of cards randomly draw a card placed in the array of I subscript.
So we can do it with an array or two arrays.
Sort of like a classic choice.
#include <stdio.h> #include <time.h> #include <stdlib.h> #include <string.h> #include < vector> #include <algorithm> #define Poker_num 54int poker[54];void Inipoker () {for (int i=0;i<poker_ num;i++) { poker[i]=i+1; }} void Suffle () {for (int i=0;i<poker_num;i++) { int index=rand ()% (poker_num-i) +i; Gets an index from I~poker_num std::swap (Poker[i],poker[index]); Swap }}void Printpoker () {for (int i=0;i<poker_num;i++) { if (i%9==0) printf ("\ n"); printf ("%4d", Poker[i]);} } int main () { Srand (Time (NULL)); Inipoker (); Printpoker (); Suffle (); printf ("\ n-------------------------------------------------------------\ n"); Printpoker ();}
The implementation of the classical shuffling algorithm C language