def bernoulli(p, u):
    """
    Generates a Bernoulli rnd variate.
    :param p: (float) success probability. Must be 0.0 < p < 1.0.
    :param u: (float) rnd number in (0,1).
    :return: (float) the Bernoulli(p) rnd variate.
    """
    return 0 if u < (1 - p) else 1