From 390b13cd20f24ad9f1f4797289c12a5aea4a3c17 Mon Sep 17 00:00:00 2001 From: chzhang Date: Sun, 1 Jan 2023 12:19:37 +0800 Subject: computation graph --- fun_math/monte_carlo/random_cut.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'fun_math/monte_carlo') 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 -- cgit v1.2.3