'Circular data distribution.
mu is the mean angle, expressed in radians between 0 and 2*pi, and
kappa is the concentration parameter, which must be greater than or
equal to zero.  If kappa is equal to zero, this distribution reduces
to a uniform random angle over the range 0 to 2*pi.'

def vonmisesvariate(self, mu, kappa):

    random = self.random
    if (kappa <= 1e-06):
        return (TWOPI * random())
    a = (1.0 + _sqrt((1.0 + ((4.0 * kappa) * kappa))))
    b = ((a - _sqrt((2.0 * a))) / (2.0 * kappa))
    r = ((1.0 + (b * b)) / (2.0 * b))
    while 1:
        u1 = random()
        z = _cos((_pi * u1))
        f = ((1.0 + (r * z)) / (r + z))
        c = (kappa * (r - f))
        u2 = random()
        if ((u2 < (c * (2.0 - c))) or (u2 <= (c * _exp((1.0 - c))))):
            break
    u3 = random()
    if (u3 > 0.5):
        theta = ((mu % TWOPI) + _acos(f))
    else:
        theta = ((mu % TWOPI) - _acos(f))
    return theta
