You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
798B

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #include <inttypes.h>
  5. int main(int argc, char** argv)
  6. {
  7. FILE *f= fopen(argv[1], "rb+");
  8. int count= atoi(argv[2]);
  9. int maxburst= atoi(argv[3]);
  10. int length, i;
  11. srand (time (0));
  12. fseek(f, 0, SEEK_END);
  13. length= ftell(f);
  14. fseek(f, 0, SEEK_SET);
  15. while(count--){
  16. int burst= 1 + random() * (uint64_t) (abs(maxburst)-1) / RAND_MAX;
  17. int pos= random() * (uint64_t) length / RAND_MAX;
  18. fseek(f, pos, SEEK_SET);
  19. if(maxburst<0) burst= -maxburst;
  20. if(pos + burst > length)
  21. continue;
  22. while(burst--){
  23. int val= random() * 256ULL / RAND_MAX;
  24. if(maxburst<0) val=0;
  25. fwrite(&val, 1, 1, f);
  26. }
  27. }
  28. return 0;
  29. }