Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Splitmix not consistent across platforms with the same seed #23

Open
psibi opened this issue Sep 14, 2019 · 6 comments

Comments

@psibi
Copy link

@psibi psibi commented Sep 14, 2019

I get different results on different platforms when started from the
same seed:

populateRandomString :: SMGen -> Text
populateRandomString smGen =
  let (char, ngen) = randomR ('A', 'Z') smGen
      (char2, gen2) = randomR ('A', 'Z') ngen
   in pack (char : [char2])

And a test code for it:

    it "random string" $ do
      let seed = (10000, 10000)
      let txt = populateRandomString (seedSMGen' seed)
      txt `shouldBe` "QH"

The above tests pass fine in Linux & OSX platform. But for Windows it
fails with the following output:

test\SplitSpec.hs:27:7: 
2) Split, Splitmax test, random string
     expected: "QH"
      but got: "SF"

Is my assumption wrong somewhere ? Note that I don't get the problem
if I go with the StdGen provided by the random package.

Issue reproducible in Azure CI: https://dev.azure.com/psibi2000/splitmix-debug/_build/results?buildId=906

@phadej

This comment has been minimized.

Copy link
Owner

@phadej phadej commented Sep 14, 2019

I tried this on windows and linux (on the same 64bit machine), in https://github.com/phadej/splitmix/compare/issue23 and I am unable to reproduce.

As RandomR goes through Int, there might could be difference between 32bit and 64bit variants, but your claim about StdGen working refutes that.

@psibi

This comment has been minimized.

Copy link
Author

@psibi psibi commented Sep 14, 2019

@phadej This is the github repository with the full code: https://github.com/psibi/splitmix-experiment

And this is a sample Azure build where it fails: https://dev.azure.com/psibi2000/splitmix-debug/_build/results?buildId=906

From looking at the build agent docs, it does seem to be 64-bit - so I don't think it's a problem because of 32bit/64bit variants. I upgraded the image to use windows 2019 server and I was able to reproduce the same issue: https://dev.azure.com/psibi2000/splitmix-debug/_build/results?buildId=908

@phadej

This comment has been minimized.

Copy link
Owner

@phadej phadej commented Sep 14, 2019

I'm still unable to reproduce. Note that second part of seed is always odd, so your first test is broken. With

diff --git a/test/SplitSpec.hs b/test/SplitSpec.hs
index a8cf2e5..416c5fc 100644
--- a/test/SplitSpec.hs
+++ b/test/SplitSpec.hs
@@ -17,16 +17,16 @@ spec :: Spec
 spec = do
   describe "Splitmax test" $ do
     it "seed/unseed" $ do
-      let seed = (10000, 10000)
+      let seed = (10000, 10001)
           gen = seedSMGen' seed
           outputSeed = unseedSMGen gen
       seed `shouldBe` outputSeed
     it "random string" $ do
-      let seed = (10000, 10000)
+      let seed = (10000, 10001)
       let txt = populateRandomString (seedSMGen' seed)
       txt `shouldBe` "QH"
     it "splitSMGen" $ do
-      let seed = (10000, 10000)
+      let seed = (10000, 10001)
           (gen1, gen2) = splitSMGen $ seedSMGen' seed
           gen1unseed = unseedSMGen gen1
           gen2unseed = unseedSMGen gen2

change the suite passes both on windows and linux.

@phadej

This comment has been minimized.

Copy link
Owner

@phadej phadej commented Sep 14, 2019

Also, I don't use stack myself, don't force me to.

@psibi

This comment has been minimized.

Copy link
Author

@psibi psibi commented Sep 15, 2019

@phadej Thanks for the pointers! I modified the code to use mkSMGen instead of trying to use seedSMGen'. This is the new code:

populateRandomString :: SMGen -> Text
populateRandomString smGen =
  let (char, ngen) = randomR ('A', 'Z') smGen
      (char2, gen2) = randomR ('A', 'Z') ngen
   in pack (char : [char2])

spec :: Spec
spec = do
  describe "Splitmax test" $ do
    it "random string" $ do
      let txt = populateRandomString $ mkSMGen 10000
      txt `shouldBe` "RK"

Note that the Azure CI test still fails in Windows (passes fine in Linux & OSX): https://dev.azure.com/psibi2000/splitmix-debug/_build/results?buildId=914

Also, I have uploaded a cabal file in the repository now.

@phadej

This comment has been minimized.

Copy link
Owner

@phadej phadej commented Sep 15, 2019

I'm still unable to reproduce it locally. That test passes both on linux and windows when I try locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.