在Windows和Linux上的不同rand()结果 [英] different rand() results on Windows and Linux

查看:567
本文介绍了在Windows和Linux上的不同rand()结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到,标准的rand()函数在Windows和Linux上给出不同的结果。当然我使用了相同的种子号(1234)。以下是几个第一个结果:



WIN:4068 213 12761 8758



LIN:479142414 465566339 961126155 1057886067

我的应用程序要求两个平台生成相同的输出。
我的选择是什么?对满足我要求的rand()有什么好的替换吗?



感谢



我在Windows7上使用MSVC 2008,在CentOS 5.5上使用gcc 4.1.2

解决方案

Boost有一个全范围的RNG ,可能具有跨平台的可重复行为。


I've noticed, that standard rand() function gives different results on Windows and Linux. Ofcourse I've used the same seed number (1234). Here are several first results:

WIN: 4068 213 12761 8758

LIN: 479142414 465566339 961126155 1057886067

My application requires that both platforms produce identical output. What are my options? Is there any good replacement for rand() that meets my requirement ?

thanks

PS. I used MSVC 2008 on Windows7, and gcc 4.1.2 on CentOS 5.5

解决方案

Boost has a wide range of RNGs, presumably with reproducible behaviour across platforms.

这篇关于在Windows和Linux上的不同rand()结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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