import math


def rand_trap(rng):
    """ Random number between 0 and 1 according to trapezoid distribution.
    a = 0
    b = 1/4
    c = 3/4
    d = 1
    Peak density is 1.333.
    """
    sixth = 1./6
    f = rng.random()
    fc = 1. - f
    if f < sixth:
        return math.sqrt(0.375 * f)
    elif fc < sixth:
        return 1. - math.sqrt(0.375 * fc)
    else:
        return 0.75*f + 0.125