diff options
| author | zhang <zch921005@126.com> | 2019-11-09 16:30:58 +0800 |
|---|---|---|
| committer | zhang <zch921005@126.com> | 2019-11-09 16:30:58 +0800 |
| commit | 9aeaa9dc06b5ecd0d3c5f98b0bf80e8af0556e4b (patch) | |
| tree | 640f439c3ff14d4a1e303586d15778ba56f2af4c | |
first commit
| -rw-r--r-- | monte_carlo_triangle.py | 27 | ||||
| -rw-r--r-- | readme.md | 0 |
2 files changed, 27 insertions, 0 deletions
diff --git a/monte_carlo_triangle.py b/monte_carlo_triangle.py new file mode 100644 index 0000000..f8167cc --- /dev/null +++ b/monte_carlo_triangle.py @@ -0,0 +1,27 @@ + +import random +import matplotlib.pyplot as plt + + +denominator = 0 +numerator = 0 + + +results = [] +for N in range(10000, 1000000, 10000): + for i in range(N): + + b = random.random() # 0-1 + a = random.random() # 0-1 + + if a < b: + denominator += 1 + + if a+(b-a) > 1-b and a+(1-b) > b-a and (b-a)+(1-b) > a: + numerator += 1 + print(N, numerator*1./denominator) + results.append(numerator*1./denominator) + +# print(results) +plt.scatter(range(len(results)), results) +plt.show() diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/readme.md |
