How to keep the sequence of random numbers (normal distributions) the same? I tried random.seed(), but it didn't work

0

Issue

I’m trying to write some replicable Monte Carlo simulation, and need to fix the seed for the random number generator (so that when other people run it, they get exactly the same result).
I tried the following codes

import numpy as np
import random
random.seed(1)
N=10
mu=[0]
sig=[[1]]
a=np.random.multivariate_normal(mu, sig, N)
print(a)

But each time I run the code, it prints a different sequence. How could this be fixed? Thanks!

Solution

random and np.random aren’t the same. If you use np.random then use np.random.seed.

Answered By – Julien

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More