Guest User

Untitled

a guest
Oct 19th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. nRand = 10000000;
  2. hit = 0;
  3. for i = 1:nRand
  4. x = rand();
  5. y = rand();
  6. z = rand();
  7.  
  8. if(x^2 + y^2 + z^2 < 1)
  9. hit = hit + 1;
  10. end
  11. end
  12.  
  13. (hit/nRand)* 8 * (3/4);
  14. %%
  15.  
  16. nRand = 10000000;
  17. hit = 0;
  18. for i = 1:nRand
  19. heads = 0;
  20. for b = 1:5
  21. if(rand() > .5)
  22. heads = heads + 1;
  23. end
  24. end
  25. if(heads == 3)
  26. hit = hit + 1;
  27. end
  28. end
  29.  
  30. (hit/nRand);
Add Comment
Please, Sign In to add comment