#5133: Random instance for Float can generate values out of requested range
---------------------------------+------------------------------------------
    Reporter:  richardsenington  |       Owner:                
        Type:  bug               |      Status:  new           
    Priority:  normal            |   Component:  libraries/base
     Version:  7.1               |    Keywords:  System.Random 
    Testcase:                    |   Blockedby:                
          Os:  Linux             |    Blocking:                
Architecture:  x86               |     Failure:  None/Unknown  
---------------------------------+------------------------------------------

Comment(by scpmw):

 This is probably a rounding issue -- while the documentation specifies a
 [0,1) range, querying a `Float` random value gives 1.0, while querying a
 `Double` gives 0.99999998. Digging deeper, the
 [http://hackage.haskell.org/packages/archive/random/latest/doc/html/src
 /System-Random.html#randomIvalDouble randomIvalDouble] implementation is
 probably to blame: It generates the random Float using from 2^32^ possible
 integer values, where single-precision `Float` only has 23 fraction bits
 and therefore will round quite a few numbers up to 1.0.

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

_______________________________________________
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to