samedi 30 avril 2016

Can C++11 PRNG be used to produce repeatable results?

I'm working on a test suite for my package, and as part of the tests I would like to run my algorithm on a block of data. However, it occured to me that instead of hardcoding a particular block of data, I could use an algorithm to generate it. I'm wondering if the C++11 <random> facilities would be appropriate for this purpose.

From what I understand, the C++11 random number engines are required to implement specific algorithms. Therefore, given the same seed they should produce the same sequence of random integers in the range defined by the algorithm parameters.

However, as far as distributions are concerned, the standard specifies that:

The algorithms for producing each of the specified distributions are implementation-defined.

(26.5.8.1 Random number distribution class templates / In general)

Which — unless I'm mistaken — means that the output of a distribution is pretty much undefined. And from what I've tested, the distributions in GNU libstdc++ and LLVM project's libc++ produce different results given the same random engines.

The question would therefore be: what would be the most correct way of producing pseudo-random data that would be completely repeatable across different platforms?




Aucun commentaire:

Enregistrer un commentaire