def select_random(object_dict, n):
    keys = list(object_dict.keys())
rate = np.array([x.rate for x in keys])
prob = rate / rate.sum()
return np.random.choice(keys, size=n, replace=True, p=prob)
Python not quite random sampling from a list of objects