为什么C ++ STDLIB rand()函数用于跨平台相同的种子给不同的价值观? [英] Why does the C++ stdlib rand() function give different values for the same seed across platforms?

查看:184
本文介绍了为什么C ++ STDLIB rand()函数用于跨平台相同的种子给不同的价值观?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,兰特()函数生成基于种子是给定的伪随机数,以及给定的平台上它总是会产生相同的序列从相同的种子数字,我想知道的是,为什么它给所有使用相同的库平台,不同的序列?即如何兰特()实施?

I understand that the rand() function generates pseudo-random numbers based on the seed it is given, and that on a given platform it will always generate the same sequence of numbers from the same seed, what I want to know is why it gives a different sequence across platforms that use the same library? I.e. how is rand() implemented?

推荐答案

C ++标准没有规定使用什么算法为rand()函数。

The C++ standard does not specify what algorithm is used for the rand() function.

该功能是通过谁写您的系统上的标准库中定义的:微软标准库随Visual Studio和GNU家伙与GCC包装标准库

The functionality is defined by whoever wrote the standard library on your system: Microsoft for the standard library included with Visual Studio, and the GNU guys for the standard library packaged with GCC.

您编译制作它得到它的库从选择,所以你可能有不同版本的同一系统的不同的编译器的标准库。问题的关键仍然是相同的:规范保证可用的功能和他们做什么;不是他们是如何做到这一点。

Your compiler is making the choice of where it gets its library from, so you may have different versions of the standard library for different compilers on the same system. The point remains the same: the specification guarantees what functions are available and what they do; not how they do it.

这篇关于为什么C ++ STDLIB rand()函数用于跨平台相同的种子给不同的价值观?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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