fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. void shuffle_sattolo(int *a, size_t size)
  6. {
  7. while (size > 1)
  8. {
  9. size--;
  10. int j = rand() % size;
  11. int tmp = a[j];
  12. a[j] = a[size];
  13. a[size] = tmp;
  14. }
  15. }
  16.  
  17. int main(int argc, char **argv)
  18. {
  19. srand(time(NULL));
  20.  
  21. int arr1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
  22. shuffle_sattolo(arr1, 14);
  23.  
  24. int arr2[] = {0, 1, 2, 3};
  25. shuffle_sattolo(arr2, 4);
  26.  
  27. for (size_t i = 0; i < 14; i++)
  28. printf("%d ", arr1[i]);
  29.  
  30. putchar('\n');
  31.  
  32. int a, b, c, d;
  33. a = arr2[0]; b = arr2[1]; c = arr2[2]; d = arr2[3];
  34. printf("%d\n", a);
  35. printf("%d\n", b);
  36. printf("%d\n", c);
  37. printf("%d\n", d);
  38.  
  39. return 0;
  40. }
Success #stdin #stdout 0s 2168KB
stdin
Standard input is empty
stdout
9 11 12 3 6 1 4 2 13 14 7 5 10 8 
2
3
1
0