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
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
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.
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'sC++
, notC
- different language, so probably not directly suitable.