import numpy as np rng = np.random.default_rng() class Player: def __init__(self) -> None: pass def play(self): n = 1 while True: if np.random.randint(2): return n else: n += 1 class Simulator: def __init__(self, N:int) -> None: self.player = Player() self.N = N def simulation(self) -> list: total = 0 for _ in range(self.N): total += self.player.play() return total def output(self, n:int) -> None: results = np.array([self.simulation() for _ in range(n)]) wins = np.full(n, self.N) wr = wins/results print(f"finished {n} times of simulation!") print("for total plays:\n\tmean\tstd") print(f"\t{np.mean(results)}\t{np.std(results)}") print("for win rates:\n\tmean\tstd") print(f"\t{np.mean(wr)}\t{np.std(wr)}") sim = Simulator(1) sim.output(100000) print(np.log(2))