bhupixb

C random number generator

Jun 23rd, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. #include "stdio.h"
  2. #include <stdlib.h>
  3. // This rand() function is not a good random number generator(People say so)
  4. /*
  5. int rand(int l, int r){
  6. static std::mt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count());
  7. std::uniform_int_distribution<int> uid(l, r); return uid(rng);
  8. }*/
  9.  
  10. signed main() {
  11. FILE *fptr = fopen("in", "w");
  12.  
  13. int t = 1, n;
  14. // fprintf(fptr, "%d\n", t);
  15. for(int i = 0; i < t; ++i) {
  16. n = rand() % 100 + 1;
  17. if(i == 0) {
  18. fprintf(fptr, "%d\n", n);
  19. }
  20. else
  21. fprintf(fptr, "\n%d\n", n);
  22. while(n--)
  23. fprintf(fptr, "%d ", rand() % 100);
  24.  
  25. }
  26. fclose(fptr);
  27. }
Add Comment
Please, Sign In to add comment