如何在MATLAB中为随机数生成器设置统一的种子? [英] How to set a unified seed for random number generators in MATLAB?
本文介绍了如何在MATLAB中为随机数生成器设置统一的种子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在编写代码并使用MATLAB中的现有函数.如果这些函数使用随机数生成器怎么办.有没有一种方法可以固定这些函数的种子而无需更改它们的代码? MATLAB中是否有执行此操作的命令?
I'm writing code and using existing functions from MATLAB. What if these functions use random number generators. Is there a way I can fix the seed of these functions without having to change their code ? Is there a command in MATLAB that does this ?
推荐答案
通常,代码将使用Matlab的内置随机数生成器.您可以使用以下内容对其进行播种:
Normally code would use Matlab's built-in random number generator. You can seed it with the following:
rng = RandStream.getDefaultStream;
rng.reset(your_seed_value_here);
一个人也可以创建RandStream
对象并使用它们(从而避免使用默认流),但这在大多数情况下都应该起作用.
One could also create RandStream
objects and use them (thereby avoiding the default stream), but this should work most of the time.
这篇关于如何在MATLAB中为随机数生成器设置统一的种子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文