import random
import math


def normal_random(mean = 0.0, variance = 1.0):
    """
        Samples from a normal distribution.

        :param mean
            The mean. Default is 0.0.
        :param variance
            The variance. Default is 1.0.
    """
    while True:
        v1 = 2.0 * random.random() - 1.0
        v2 = 2.0 * random.random() - 1.0
        s = v1 * v1 + v2 * v2
        if s <= 1.0:
            break
    result = math.sqrt(-2.0 * math.log(s) / s) * v1
    return mean + math.sqrt(variance) * result