lundi 29 juin 2015

How to generate independent identically distributed (iid) random variables in python

I am developing a simulation infrastructure with some random events (for instance, sources that generate output with a certain probability). So far I've been doing it using the random.random() function. Ex:

class source:
    def output(self, x):
        if(random.random()<=x):
            return foo
a = []
for i in xrange(10)
    a.append(source())

for i in xrange(1000):
    for j in xrange(len(a)):
        a[j].output()

From what I understand, all of the sources in my list "a" will get random numbers from the same pseudo-random LFSR source, so a[0] will get a sample, then a[1] will get the next one, then a[2], etc. If random.ramdom() generated a truly random sequence, I believe this would still generate 10 iid subsets of values, however, since I am assuming that python uses an LFSR, or a similar scheme, where each subsequent sample depends on the previous sample, taking several subsets of these samples may or may not be independent and identically distributed.

I have two questions:

  1. What kind of distributions do I actually get using my pseudocode or something similar to that
  2. How do I get several iid random variables in python?

I looked at other stack overflow posts, like this one for example: Generate multiple independent random streams in python but they don't answer my question.




Aucun commentaire:

Enregistrer un commentaire