fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. int randomInteger(int low, int high)
  6. {
  7. int k;
  8. double d;
  9. d = (double)rand() / ((double)RAND_MAX + 1);
  10. k = (int) (d * (high - low + 1));
  11. return low + k;
  12. }
  13.  
  14. void randomize()
  15. {
  16. srand(time(NULL));
  17. }
  18.  
  19. int main() {
  20.  
  21. randomize();
  22. int i;
  23. for (i = 0; i < 100; i++)
  24. printf("%d ", randomInteger(0, 9));
  25. return 0;
  26. }
Success #stdin #stdout 0s 2112KB
stdin
Standard input is empty
stdout
9 6 5 7 9 6 7 2 7 7 0 2 0 2 0 3 7 3 7 1 8 6 3 2 0 7 1 4 7 8 9 6 4 4 4 4 0 1 7 8 8 7 0 9 9 1 2 6 4 9 8 3 5 1 5 5 9 6 0 6 4 9 3 8 4 7 3 5 8 0 3 7 7 4 6 6 5 8 3 9 7 1 2 2 3 8 8 2 4 9 9 8 8 2 7 3 9 0 9 7