2016-11-07 19:35:17 -07:00
|
|
|
#include<stdio.h>
|
|
|
|
#include<stdlib.h>
|
|
|
|
#include<math.h>
|
|
|
|
#include<time.h>
|
|
|
|
|
|
|
|
#define CARD_MAX 51
|
|
|
|
#define len(x) sizeof(x)/sizeof(x[0])
|
|
|
|
|
|
|
|
void print_deck (int *deckOfCards);
|
2017-01-21 23:12:08 -07:00
|
|
|
void shuffel (int *array);
|
2016-11-07 19:35:17 -07:00
|
|
|
|
|
|
|
int main (int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int deckOfCards[CARD_MAX];
|
|
|
|
|
|
|
|
time_t t;
|
|
|
|
srand((unsigned) time(&t));
|
|
|
|
|
|
|
|
|
|
|
|
/* Clubs > Diamonds > Hearts > Spades
|
|
|
|
* 0-12 13-25 26-38 39-51
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (i = 0; i<CARD_MAX; i++){
|
|
|
|
deckOfCards[i]=i;
|
|
|
|
}
|
|
|
|
|
2017-01-21 23:12:08 -07:00
|
|
|
shuffel(deckOfCards);
|
2016-11-07 19:35:17 -07:00
|
|
|
|
|
|
|
print_deck(deckOfCards);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void print_deck(int *deckOfCards){
|
|
|
|
int i;
|
|
|
|
|
2017-01-21 22:02:48 -07:00
|
|
|
for (i = 0; i<=CARD_MAX; i++){
|
2016-11-07 19:35:17 -07:00
|
|
|
printf("%d\n", deckOfCards[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-21 23:12:08 -07:00
|
|
|
void shuffel (int *array){
|
2016-11-07 19:35:17 -07:00
|
|
|
|
2017-01-21 23:12:08 -07:00
|
|
|
int i, rn, a , tmp;
|
2016-11-07 19:35:17 -07:00
|
|
|
|
2017-01-21 23:12:08 -07:00
|
|
|
rn = rand();
|
|
|
|
|
|
|
|
for (i=CARD_MAX; i >= CARD_MAX/CARD_MAX ;i--){
|
2016-11-07 19:35:17 -07:00
|
|
|
|
2017-01-21 23:12:08 -07:00
|
|
|
a = rn % i;
|
|
|
|
tmp = array[a];
|
|
|
|
array[a] = array[i];
|
2017-01-21 22:12:28 -07:00
|
|
|
array[i] = tmp;
|
2016-11-07 19:35:17 -07:00
|
|
|
}
|
|
|
|
}
|