Assumptions:
Each person chooses a room independently from the other people
Each person is equally likely to choose any of the rooms
import matplotlib.pyplot as plt
import pandas as pd
import random
random.seed(269027)
number_of_people = 15
number_of_rooms = 3
people = [*range(1, number_of_people + 1, 1)]
rooms = [*range(1, number_of_rooms + 1, 1)]
simulations = [1, 10, 50, 100, 500, 1000, 5000, 10000, 50000, 100000, 500000, 1000000, 5000000]
Using the properties of numbers and math, when all 3 rooms are equal size we know the difference between the largest and smallest room has to be 0
estimated_probability = []
for s in simulations:
print('# of simulations:' + str(s))
room_size_delta = []
for i in range(s):
room_members = [[] for _ in range(number_of_rooms)]
for p in people:
room_assignment = random.choice(rooms)
room_members[room_assignment - 1] += [p]
room_size_delta += [max([len(x) for x in room_members]) - min([len(x) for x in room_members])]
probability = len([x for x in room_size_delta if x == 0])/len(room_size_delta)
print('estimated probability of equal rooms: ' + str(probability))
estimated_probability += [[s, probability]]
plt.figure(figsize=(12,6))
plt.hist(room_size_delta, density=True, bins=15)
plt.ylabel('Frequency')
plt.xlabel('Delta between largest room and smallest room')
probability_trend = pd.DataFrame(estimated_probability)
probability_trend.columns = ['simulations', 'probability']
plt.figure(figsize=(12,6))
plt.plot(probability_trend.simulations, probability_trend.probability)
plt.xlabel('Number of simulations')
plt.ylabel('Estimated probability of equal size rooms')