diff options
| author | chzhang <zch921005@126.com> | 2023-01-01 12:19:37 +0800 |
|---|---|---|
| committer | chzhang <zch921005@126.com> | 2023-01-01 12:19:37 +0800 |
| commit | 390b13cd20f24ad9f1f4797289c12a5aea4a3c17 (patch) | |
| tree | b502d903ac334654c6b019c6eace48f98908951b /fun_math/monte_carlo | |
| parent | 1744bfdfe95b737eb4ed079325e0679ab9e16991 (diff) | |
computation graph
Diffstat (limited to 'fun_math/monte_carlo')
| -rw-r--r-- | fun_math/monte_carlo/random_cut.py | 10 |
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 |
