Skip to content

Commit

Permalink
Avoid discrepancies between Double generation and GHC versions
Browse files Browse the repository at this point in the history
Something has changed from ghc-9.0 to ghc-9.2 that often results in
generation of slightly different `Double` values. This commit carefully
chooses initial seed in such a way that generated values are exactly
the same throughout all supported ghc versions.
  • Loading branch information
lehins committed Oct 27, 2024
1 parent 0d8caf6 commit a20f1c2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions src/System/Random.hs
Original file line number Diff line number Diff line change
Expand Up @@ -340,11 +340,11 @@ class Random a where
-- closed interval /[lo,hi]/, together with a new generator. It is unspecified
-- what happens if /lo>hi/, but usually the values will simply get swapped.
--
-- >>> let gen = mkStdGen 2021
-- >>> let gen = mkStdGen 26
-- >>> fst $ randomR ('a', 'z') gen
-- 't'
-- >>> fst $ randomR ('z', 'a') gen
-- 't'
-- 'z'
-- >>> fst $ randomR ('a', 'z') gen
-- 'z'
--
-- For continuous types there is no requirement that the values /lo/ and /hi/ are ever
-- produced, but they may be, depending on the implementation and the interval.
Expand All @@ -353,8 +353,8 @@ class Random a where
-- defined on per type basis. For example product types will treat their values
-- independently:
--
-- >>> fst $ randomR (('a', 5.0), ('z', 10.0)) $ mkStdGen 2021
-- ('t',6.240232662366564)
-- >>> fst $ randomR (('a', 5.0), ('z', 10.0)) $ mkStdGen 26
-- ('z',7.27305019146949)
--
-- In case when a lawful range is desired `uniformR` should be used
-- instead.
Expand Down
6 changes: 3 additions & 3 deletions src/System/Random/Stateful.hs
Original file line number Diff line number Diff line change
Expand Up @@ -299,16 +299,16 @@ withMutableGen_ fg action = thawGen fg >>= action
-- ====__Examples__
--
-- >>> import System.Random.Stateful
-- >>> let pureGen = mkStdGen 137
-- >>> let pureGen = mkStdGen 139
-- >>> g <- newIOGenM pureGen
-- >>> randomM g :: IO Double
-- 0.5728354935654512
-- 0.33775117339631733
--
-- You can use type applications to disambiguate the type of the generated numbers:
--
-- >>> :seti -XTypeApplications
-- >>> randomM @Double g
-- 0.6268211351114488
-- 0.9156875994165681
--
-- @since 1.2.0
randomM :: forall a g m. (Random a, RandomGen g, FrozenGen g m) => MutableGen g m -> m a
Expand Down

0 comments on commit a20f1c2

Please sign in to comment.