在 Julia 随机数生成器中设置随机种子 [英] set the random seed in julia generator of random numbers

查看:24
本文介绍了在 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

解决方案

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.

这篇关于在 Julia 随机数生成器中设置随机种子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆