Based on a programming problem I saw recently, I am wondering if it is possible to simulate the following situation more efficiently:
- There are $N$ teams playing in a tournament.
- Each team plays every other team $K$ times.
- Each team has $1/2$ chance of winning every game it plays.
- There are no draws: in each game, one game wins and one game loses.
- All game outcomes are independent.
- After the tournament is complete, vector $S$ contains $N$ integers; $S[i]$ gives the number of wins by team $i$.
I am looking for a probability distribution with parameters $(N, K)$ with a typical realization $S$. I can simulate $S$ by drawing $K * N * (N - 1)$ Bernoulli random variables (see code below).
Question: Is there a known distribution (as a function of $(N, K)$) that I can sample from to get realizations $S$?.
Here is a sample Python code for $N = 8$ and $K = 3$.
from itertools import combinations
import random
random.seed(0)
n_teams = 8
k_playoffs = 3
def simulate_naive(n_teams=n_teams, k_playoffs=k_playoffs):
# store score for each team
# eventually, the score[i] contains the number of times
# team i has won
scores = [0] * n_teams
# iterate over all pairs of teams
for i, j in combinations(range(n_teams), 2):
# each pair of teams plays k times
for k in range(k_playoffs):
# within each game, each team has 50/50 chance of winning
if random.random() < 0.5: # condition is met 50% of the time
scores[i] += 1
else:
scores[j] += 1
return scores
example_scores = simulate_naive()
print(example_scores)
# [8, 9, 13, 4, 14, 11, 12, 13]