

def test_avg_std(self):
    g = random.Random()
    N = 5000
    xx = [(i / float(N)) for i in xrange(1, N)]
    dists = [(g.uniform, (1.0, 10.0), ((10.0 + 1.0) / 2), (((10.0 - 1.0) ** 2) / 12)), (g.expovariate, (1.5,), (1 / 1.5), (1 / (1.5 ** 2))), (g.paretovariate, (5.0,), (5.0 / (5.0 - 1)), (5.0 / (((5.0 - 1) ** 2) * (5.0 - 2)))), (g.weibullvariate, (1.0, 3.0), gamma((1 + (1 / 3.0))), (gamma((1 + (2 / 3.0))) - (gamma((1 + (1 / 3.0))) ** 2)))]
    if hasattr(g, 'triangular'):
        dists.append((g.triangular, (0.0, 1.0, (1.0 / 3.0)), (4.0 / 9.0), ((7.0 / 9.0) / 18.0)))
    for (variate, args, mu, sigmasqrd) in dists:
        x = xx[:]
        g.random = getattr(x, 'pop')
        y = []
        for i in xrange(len(x)):
            try:
                y.append(variate(*args))
            except IndexError:
                pass
        s1 = s2 = 0
        for e in y:
            s1 += e
            s2 += ((e - mu) ** 2)
        N = len(y)
        self.assertAlmostEqual((s1 / N), mu, 2)
        self.assertAlmostEqual((s2 / (N - 1)), sigmasqrd, 2)

dataset/ETHPy150Open anandology/pyjamas/examples/libtest/RandomModuleTest.py RandomModuleTest.test_avg_std/original