import random rng = random.Random(42) heads = sum(rng.randint(0, 1) for _ in range(1000)) print(heads, heads / 1000) # 514, 0.514