Advertisement
Guest User

Untitled

a guest
May 6th, 2012
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. #include <time.h>
  2. #include <stdio.h>
  3. #include <limits.h>
  4. #include <stdlib.h>
  5.  
  6. #define N_ITERATIONS 20000
  7.  
  8. int main(){
  9. unsigned long int i, j, k, count, thresh, two_streak=0, total=0;
  10. double avg_sum=0;
  11. srand((unsigned)time(NULL));
  12. for(i=0;i<N_ITERATIONS;i++){
  13. thresh = rand();
  14. for(j=0;j<N_ITERATIONS;j++){
  15. count=0;
  16. for(k=0;k<14;k++){
  17. if(rand()<thresh)
  18. count++;
  19. }
  20. if(count==10){
  21. if(rand()<thresh && rand()<thresh)
  22. two_streak++;
  23. total++;
  24. }
  25. }
  26. }
  27. printf("%lf\n", (double)two_streak/(double)total);
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement