如何在Matlab中设置相同的初始种子随机数? [英] How to set the same initial seed random numbers in Matlab?

查看:369
本文介绍了如何在Matlab中设置相同的初始种子随机数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个matlab代码,其中包含一堆随机数,例如:unifrnd(0,1)normrnd(mu,sigma),这种功能会一遍又一遍地重复.

I have a matlab code which has a bunch of random numbers such as: unifrnd(0,1), normrnd(mu,sigma), this sort of functions get repeated over and over again.

有什么办法可以修复生成的随机数?意思是,一旦得到一些结果,我就运行代码,在第二次运行中,我得到不同的结果(如预期的那样).但是,我想尝试一些经验,如果可以修复初始种子,使两次运行的所有随机性都相同,那将非常有帮助.

Is there any way I can fix the random numbers that are generated? Meaning, I run the code once I get some results, on the second run I get different results (as expected). However, I want to make some experiences and it would be really helpful if I could fix the initial seed so that all randomness would be the same on the two runs.

谢谢, V

是否可以进行以下工作:rand('seed', 57)

edit: Would something like this work: rand('seed', 57)

推荐答案

根据文档

rng(seed);

设置随机数生成器的种子.

sets the seed of the random number generator.

这篇关于如何在Matlab中设置相同的初始种子随机数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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