13 lines
506 B
Python
13 lines
506 B
Python
import random
|
|
def count_hits(n_points, seed):
|
|
"""Сколько случайных точек из квадрата [0,1]x[0,1] попало в четверть круга."""
|
|
rng = random.Random(seed) # свой генератор у каждой порции
|
|
hits = 0
|
|
for _ in range(n_points):
|
|
x, y = rng.random(), rng.random()
|
|
if x * x + y * y <= 1.0:
|
|
hits += 1
|
|
return hits
|
|
def estimate_pi_serial(n_points):
|
|
return 4 * count_hits(n_points, seed=0) / n_points
|