A language-learning app is testing two wordings of its evening reminder. Each wording went to its own group of users, and the team counted how many of them opened the app that evening.
They analyse it the Bayesian way. Each wording has an unknown return rate , the chance that a user who gets it comes back. Before the test, both rates get the same prior. After the test, each wording has its own Beta posterior.
The question that decides the launch is: how probable is it that B's true return rate is higher than A's? That is . Two Beta curves don't hand over this number directly, so the team simulates it:
That fraction is an empirical probability, the same count-over-total idea as a relative frequency of real events. The more rounds you run, the closer it settles to the true .
Task: write chance_b_wins(a, b, prior, draws, seed).
a and b are pairs (returned, sent): how many users came back, out of how many were sent that wording.prior is the pair (alpha0, beta0), shared by both wordings.draws rounds that B won, rounded to 4 decimal places.So the judge can replay your simulation exactly:
rng = random.Random(seed);rng.betavariate(alpha, beta) first for A, then for B, each with that wording's posterior parameters;