samedi 31 décembre 2016

Is there any way to generate uncorrelatted random variables using python?

Suppose I want to generate two random variables X,Y which are uncorrelated and uniformly distributed in [0,1].

The very naive code to generate such is the flowing, which calls the random function twice:

import random xT=0 yT=0 xyT=0 for i in range(20000):
    x = random.random()
    y = random.random()
    xT += x
    yT += y
    xyT += x*y

xyT/2000-xT/2000*yT/2000

However, the random number is really the pseudo-random number which is generated by a formula, therefore they are correlated.

Question is, how to generated two random variables uncorrelated or correlate as less as possible.




Aucun commentaire:

Enregistrer un commentaire