[GHC] #8899: StdGen does not generate 0

GHC ghc-devs at haskell.org
Tue Jul 8 12:58:41 UTC 2014


#8899: StdGen does not generate 0
-------------------------------------+------------------------------------
        Reporter:  novadenizen       |            Owner:
            Type:  bug               |           Status:  new
        Priority:  normal            |        Milestone:
       Component:  libraries/random  |          Version:  7.9
      Resolution:                    |         Keywords:
Operating System:  Unknown/Multiple  |     Architecture:  Unknown/Multiple
 Type of failure:  Other             |       Difficulty:  Unknown
       Test Case:                    |       Blocked By:
        Blocking:                    |  Related Tickets:
-------------------------------------+------------------------------------

Comment (by thomie):

 The `StdGen` indeed never generates `0`.

 This follows from the following line in the function `stdNext` (`z'` is
 the next generated `Int`):
 {{{#!haskell
 z' = if z < 1 then z + 2147483562 else z
 }}}

 I checked the paper, and this is as intended. The range should be [1,
 2147483562]. novadenizen's script also finds these:
 {{{#!haskell
 Just 885777925 -- v == 1
 Just 2217242596 -- v == 2147483562
 }}}

 Here's a [https://github.com/haskell/random/pull/7 pull request].

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8899#comment:6>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list