all Python 3randomfunction
random.vonmisesvariate
distributions
A random angle from the von Mises distribution (a circular analogue of the normal) with mean mu and concentration kappa; the result is in [0, 2π].
Syntax
random.vonmisesvariate(mu, kappa)
kappa controls concentration: at kappa = 0 there is none at all and you get a uniform angle over the whole circle, while for large kappa the spread around mu is close to normal with a standard deviation of about 1/sqrt(kappa). The result is an angle in radians that wraps at 2π, so plain arithmetic averaging is wrong — the "mean" of 0.1 and 6.2 radians comes out as 3.15, pointing the opposite way.
Examples
import random, math
print(0.0 <= random.vonmisesvariate(0.0, 1.0) <= 2 * math.pi) # → True
print(0.0 <= random.vonmisesvariate(0.0, 0.0) <= 2 * math.pi) # → True
print(abs(random.vonmisesvariate(math.pi, 500.0) - math.pi) < 0.5) # → True
print(0.0 <= math.degrees(random.vonmisesvariate(0.0, 4.0)) <= 360.0) # → True
print(all(0.0 <= random.vonmisesvariate(math.pi, 2.0) <= 2 * math.pi for _ in range(1000))) # → True
See also
Open in the full glossarydocs.python.orgReport an inaccuracy