imneme / pcg-cpp

PCG — C++ Implementation
Apache License 2.0
735 stars 98 forks source link

Fix portability issues between Clang and Gcc for non-compliant SeedSeq (non-reentrant) #68

Closed ph4r05 closed 3 years ago

ph4r05 commented 3 years ago

This PR addresses issue #67. tldr: clang and gcc generates different streams when seeded from another generator on different platforms.

This is PoC, I am not a template expert in C++, there is probably a nicer way to implement this. e.g., I have a redundant parameter unused in the newly added constructor

engine(typename sm::stream_state stream_seed, bool unused)

so it is correctly selected when needed as I had a conflict with

https://github.com/imneme/pcg-cpp/blob/5b5cac8d61339e810c5dbb4692d868a1d7ca1b2d/include/pcg_random.hpp#L484

This PR uses GNU GCC evaluation order. Thus after merging this PR the stream generates the same result as it generates with GNU GCC.

ph4r05 commented 3 years ago

@imneme updated according to the discussion in #67.

As we figured out, bug I was experiencing was caused by non-compliant SeedSeq. The one we are using is non-reentrant, thus generates different values for each call.