def sample(m, colors):
    """
    Parameters
    ----------
    m : number balls to draw from the urn
    colors : one-dimensional array of number balls of each color in the urn
    Returns
    -------
    One-dimensional array with the same length as `colors` containing the
    number of balls of each color in a random sample.
    """
remaining = np.cumsum(colors[::-1])[::-1]
result = np.zeros(len(colors), dtype=np.int)
for i in range(len(colors) - 1):
    if m < 1:
        break
result[i] = np.random.hypergeometric(colors[i], remaining[i + 1], m)
m -= result[i]
result[-1] = m
return result
Numpy drawing from urn