Advertisement
cd62131

Random Cards

Mar 20th, 2014
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.40 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. int main(void) {
  5.   int i, cards[50];
  6.   srand((unsigned) time(NULL));
  7.   for (i = 0; i < 50; i++) cards[i] = i + 1;
  8.   for (i = 49; i >= 1; i--) {
  9.     int t, j = (int) ((rand() / ((double) RAND_MAX + 1.0)) * i);
  10.     t = cards[i]; cards[i] = cards[j]; cards[j] = t;
  11.   }
  12.   for (i = 0; i < 50; i += 5) printf("%d ", cards[i]); puts("");
  13.   return 0;
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement