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
The seed() method is used to initialize the random number generator. The random number generator needs a number to start with (a seed value), to be able to generate a random number. By default the random number generator uses the current system time.
set seed (value) where value specifies the initial value of the random number seed. Syntax: set.seed(123) In the above line,123 is set as the random number value. The main point of using the seed is to be able to reproduce a particular sequence of 'random' numbers. and sed(n) reproduces random numbers results by seed.
Random number generation in Julia uses the Xoshiro256++ algorithm by default, with per- Task state. Other RNG types can be plugged in by inheriting the AbstractRNG type; they can then be used to obtain multiple streams of random numbers.
The function srand () is used to provide seed for generating random numbers while rand () function generates the next random number in the sequence.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With