Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set the random seed in julia generator of random numbers

Tags:

julia

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

like image 322
user2820579 Avatar asked Jul 29 '14 00:07

user2820579


People also ask

How do you seed a random number generator?

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.

What is set seed in random?

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.

How do you get a random number in Julia?

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.

What command creates a seed using time for a random number generator?

The function srand () is used to provide seed for generating random numbers while rand () function generates the next random number in the sequence.


1 Answers

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.

like image 200
IainDunning Avatar answered Sep 19 '22 14:09

IainDunning