Windows等效的POSIX srandom(...)和random()函数? [英] Windows-equivalent of POSIX srandom(...) and random() functions?

查看:465
本文介绍了Windows等效的POSIX srandom(...)和random()函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试将一些代码从UNIX移植到Windows,并且我需要实现POSIX srandom(x)random()函数,这些函数对于给定的种子x生成与第一个种子相同的数字序列符合POSIX.1-2001. Windows上有哪些可用选项?

I'm trying to port some code over from UNIX to Windows, and I need an implementation of POSIX srandom(x) and random() functions that, for a given seed x, generate the same number sequence as the one that conforms to POSIX.1-2001. What are some of the available options on Windows?

推荐答案

srandom和family是glibc的成员.您可能可以复制只要它与许可证兼容,就可以从glibc 源代码中随机/随机进入您的应用程序.如果您正在寻找另一种实现方式,那么任何小巧的设计

srandom and family are members of glibc. You can probably copy the source code from glibc for srandom/random into your application, as long as it's license compatible. If you're looking for another implementation, any small amou

请记住,POSIX实际上是接口一致性,而不是实现一致性–它实际上没有说明生成它的机制,也不是得出的数字应该是什么.

Bear in mind, POSIX is actually interface conformance, and not implementation conformance - it doesn't actually state what the mechanism is for generating it, nor what the resulting numbers should be.

如果您希望在多个平台上保证相同的数字序列,那么您不应该依赖任何随机数生成器的标准库实现,您应该自己制作或回收一个已知的实现.

if you're looking to guarantee the same number sequence across multiple platforms, then you should not rely on the standard library implementation of any of the random number generators, you should be making your own, or recycling a known implementation.

如JWWalker的评论中所述,有一个相当不错的

As mentioned in a comment by JWWalker, there's a pretty good boost random implementation, which provides a nice set of C++ classes for random numbers, but that's C++, not C - different language, so probably not directly suitable.

这篇关于Windows等效的POSIX srandom(...)和random()函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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