lundi 19 septembre 2016

Parallel random distribution

I have two iterators in python and both should follow the same "random" distribution (both should run in parallel). For instance:

class Iter1(object):
   def __iter__(self):
       for i in random_generator():
          yield i

class Iter2(object):
   def __iter__(self):
       for i in random_generator():
          yield i

for el1, el2 in zip(Iter1(), Iter2()):
    print '{} {}'.format(el1, el2)

output should be somethig like:

0.53534 0.53534
0.12312 0.12312
0.19238 0.19238

How can I define random_generator() in a way that it creates the same random distributions in parallel for both iterators.

Note:

  • They should run in parallel
  • I can't generate the sequence in advance (it is a streaming, so I don't know the size of the sequence)

Thanks.




Aucun commentaire:

Enregistrer un commentaire