mardi 17 novembre 2020

Python random number generator giving the same value every time

I am using Python for a sampling problem. Part of the problem requires the diagonal of a matrix to be filled with either a '1' or '-1' with equal probability of either.

I am trying to use random.choice as shown below but the list I get always contains only'1' or '-1'

k = 10 
diag = []   
for i in range(0,k):
    diag.append(random.choice((1,-1)))

I have looked up seeding at different points by doing things like:

random.seed(numpy.sin(time.clock()))

and placing the seed in the for loop before the random choice is made but I get the same outcome.

Does anyone have an idea of how to solve this problem?




Aucun commentaire:

Enregistrer un commentaire