fork download
  1. #include <stdio.h>
  2. #include <time.h>
  3.  
  4. int main(void)
  5. {
  6. int numbers[52];
  7. int i, j, temp;
  8. srand(time(NULL));
  9.  
  10. // putting numbers from 1 to 52 into the 'numbers' array
  11. for(i=0; i<52; i++)
  12. numbers[i] = i + 1;
  13.  
  14. // shuffling using Fisher-Yates shuffle algorithm
  15. for(i=51; i>=1; i--)
  16. {
  17. j = rand()%(i+1);
  18. temp = numbers[i];
  19. numbers[i] = numbers[j];
  20. numbers[j] = temp;
  21. }
  22.  
  23. // printing the array
  24. for(i=0; i<52; i++)
  25. printf("%d, ", numbers[i]);
  26.  
  27. return 0;
  28. }
Success #stdin #stdout 0s 2248KB
stdin
Standard input is empty
stdout
37, 50, 25, 5, 16, 14, 47, 22, 8, 51, 33, 9, 10, 49, 41, 2, 45, 28, 40, 26, 23, 36, 35, 24, 46, 4, 38, 48, 20, 11, 52, 39, 13, 29, 15, 31, 1, 34, 18, 43, 6, 44, 7, 3, 12, 21, 27, 17, 30, 42, 32, 19,