samedi 30 septembre 2017

Numpy random.seed not working from __init__ to other methods

I have a class with constructor and method as below:

import numpy.random as random
class practiceObject(object):

    def __init__(self):

        random.seed(10)

    def getRandom(self, x):

        rd = random.randint(x)
        return rd

Now I would figure this means that for the same x I pass into "getRandom", the same value should be returned. And yet:

myObject = practiceObject()
print myObject.getRandom(100)
print myObject.getRandom(100)
>>9
>>15

Why is this happening, and what can I do to ensure each call to getRandom with the same x value will return the same value?




Aucun commentaire:

Enregistrer un commentaire