summaryrefslogtreecommitdiff
path: root/fun_math
diff options
context:
space:
mode:
Diffstat (limited to 'fun_math')
-rw-r--r--fun_math/monte_carlo/random_cut.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/fun_math/monte_carlo/random_cut.py b/fun_math/monte_carlo/random_cut.py
index e69de29..7b63624 100644
--- a/fun_math/monte_carlo/random_cut.py
+++ b/fun_math/monte_carlo/random_cut.py
@@ -0,0 +1,10 @@
+import random
+import math
+freq = 0
+N = 100000
+for i in range(N):
+ p1 = random.random()
+ p2 = random.random()
+ if math.fabs(p1-p2) <= 0.5:
+ freq += 1
+print(freq/N) \ No newline at end of file