Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. #include <stdint.h>
  2. #include <stdbool.h>
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5.  
  6. //#define MAX_BLOCKS (5859375000ull) /* 3TB / 512 */
  7. #define MAX_BLOCKS (10000000)
  8. #define TRAJ (100000ull)
  9.  
  10. static bool genbool(int p_bad) {
  11. int raw = rand() % 100;
  12. return (raw < p_bad);
  13. }
  14.  
  15. int main(int argc, char *argv[]) {
  16. int p_bad;
  17. int to_sample;
  18. int traj;
  19. bool match;
  20.  
  21. uint64_t blocks_to_sample;
  22. uint64_t found, missed;
  23.  
  24. uint64_t i, j;
  25.  
  26. // % of blocks bad
  27. for (p_bad = 1; p_bad < 100; p_bad++) {
  28. // % to sample
  29. for (to_sample = 1; to_sample < 100; to_sample++) {
  30. blocks_to_sample = (MAX_BLOCKS * to_sample) / 1000000;
  31. found = 0;
  32. missed = 0;
  33.  
  34. for (traj = 0; traj < TRAJ; traj++) {
  35. match = false;
  36. for (i = 0; i < blocks_to_sample; i++) {
  37. match |= genbool(p_bad);
  38. if (match)
  39. break;
  40. }
  41.  
  42. if (match)
  43. found++;
  44. else
  45. missed++;
  46. }
  47.  
  48. // For |p_bad| percent blocks bad, |to_sample| % sampled,
  49. // found/{found + missed} percent of the time we found
  50. // the thing.
  51. printf("p_bad=%d (%lu), to_sample=%d (%lu %f percent), pct=%f\n",
  52. p_bad, (p_bad * MAX_BLOCKS) / 100,
  53. to_sample, blocks_to_sample, (1.0 * blocks_to_sample) / MAX_BLOCKS * 100,
  54. (1.0 * found) / (found + missed) * 100);
  55. }
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement