如何在Matlab中设置相同的初始种子随机数?

编程入门 行业动态 更新时间:2024-10-27 05:36:55
本文介绍了如何在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中设置相同的初始种子随机数?

本文发布于:2023-11-08 08:07:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1568822.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:随机数   种子   如何在   Matlab

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!