random_shuffle算法 - 是否产生没有随机生成函数的相同结果? [英] random_shuffle algorithm - are identical results produced without random generator function?

查看:530
本文介绍了random_shuffle算法 - 是否产生没有随机生成函数的相同结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果随机生成函数未提供给标准库中的random_shuffle算法,那么如果提供相同的数据,程序的连续运行是否会产生相同的随机序列?



例如,如果

  std :: random_shuffle(filenames.begin(),filenames.end()); 

在程序的连续运行中的目录中对文件名的相同列表执行,

25.2.11只是说元素是以均匀分布的方式进行混洗的。它不保证在后台使用哪个RNG(除非你传递一个),所以你不能依赖任何这样的行为。



为了保证相同的shuffle结果,你需要提供自己的RNG提供这些保证,但我怀疑即使如果你更新标准库random_shuffle算法本身可以改变效果。


If a random generator function is not supplied to the random_shuffle algorithm in the standard library, will successive runs of the program produce the same random sequence if supplied with the same data?

For example, if

std::random_shuffle(filenames.begin(), filenames.end());

is performed on the same list of filenames from a directory in successive runs of the program, is the random sequence produced the same as that in the prior run?

解决方案

25.2.11 just says that the elements are shuffled with uniform distribution. It makes no guarantees as to which RNG is used behind the scenes (unless you pass one in) so you can't rely on any such behavior.

In order to guarantee the same shuffle outcome you'll need to provide your own RNG that provides those guarantees, but I suspect even then if you update your standard library the random_shuffle algorithm itself could change effects.

这篇关于random_shuffle算法 - 是否产生没有随机生成函数的相同结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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