1

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?

Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084
Michał Górny
  • 18,713
  • 5
  • 53
  • 76

2 Answers2

2

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

That would be obvious: write your own distribution. As you yourself pointed out, the engines are cross-platform since they implement a specific algorithm. It's the distributions that are implementation-defined.

So write the distributions yourself.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
0

Please see this answer: https://stackoverflow.com/a/34962942/1151329

I had exactly this problem and writing my own distributions worked perfectly. I got the same sequences across linux, OSx, windows, x86 and ARM.

Community
  • 1
  • 1
Arno Duvenhage
  • 1,910
  • 17
  • 36