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

查看:330
本文介绍了在julia随机数生成器中设置随机种子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用随机数生成器对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)

相同的H矩阵

推荐答案

更新的答案(从Julia 0.7开始).

Updated answer, for Julia 0.7 onwards.

import Random
Random.seed!(1234)
dim = 5
A = randn(dim,dim)
H = (A + A')/sqrt(2)

先前的答案,对于Julia 0.6及更早版本.

Previous answer, for Julia 0.6 and earlier.

您正在寻找 srand函数,例如

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天全站免登陆