问题
I would like to do a couple of checkings using the random generator for normal distributed numbers in julia. So what I would like is to obtain the same sequence of pseudo-random numbers.
Actually, I do random matrices, so I would like that both of my programs generate:
A = randn(dim,dim)
H = (A + A')/sqrt(2)
the same H-matrix
回答1:
Updated answer, for Julia 0.7 onwards.
import Random
Random.seed!(1234)
dim = 5
A = randn(dim,dim)
H = (A + A')/sqrt(2)
Previous answer, for Julia 0.6 and earlier.
You are looking for the srand function, e.g.
srand(1234)
dim = 5
A = randn(dim,dim)
H = (A + A')/sqrt(2)
Will always produce the same results.
回答2:
In Julia 0.7/1.0, you can use Random.seed!(1234);
https://docs.julialang.org/en/v1/stdlib/Random/index.html#Generators-(creation-and-seeding)-1
来源:https://stackoverflow.com/questions/25006370/set-the-random-seed-in-julia-generator-of-random-numbers