def rounding_with_prob(vec, p):
    """
    Rounds a vector to 0 and 1 according to the value of its entries,
    with threshold p. If vec is a vector uniformly generated from 0 and 1
    then p indicates the probility of being 1.
    """

    for index in range(vec.size):
        vec[index] = vec[index] < p
    return vec