fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. int main(void) {
  6. // your code goes here
  7. int i, idx = 0;
  8. int arr[45];
  9.  
  10. srand(time(NULL));
  11. // init
  12. for(i=0; i < 45; i++){
  13. arr[i] = (i + 1);
  14. }
  15.  
  16. // shuffle
  17. for(i=0; i < 10; i++){
  18. // get rand idx
  19. int rnd_idx = rand()%(45-i);
  20. // swap
  21. int tmp = arr[45-1-i];
  22. arr[45-1-i] = arr[rnd_idx];
  23. arr[rnd_idx] = tmp;
  24. }
  25.  
  26. // output
  27. for(i=0; i < 10; i++){
  28. printf("%02d,", arr[45-1-i]);
  29. }
  30.  
  31. return 0;
  32. }
  33.  
Success #stdin #stdout 0s 2160KB
stdin
Standard input is empty
stdout
18,13,25,10,35,40,29,32,02,31,