[GHC] #5133: Random instance for Float can generate values out of requested range

GHC cvs-ghc at haskell.org
Fri Jun 24 18:00:48 CEST 2011


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

Comment(by rrnewton):

 If you look at the Java float RNG they discuss a problem with using >24
 bits of randomness for generating floats:

 http://download.oracle.com/javase/1.4.2/docs/api/java/util/Random.html#nextFloat()

 I'm of a mind to use the 24-bit solution that they use (and 53 for
 doubles) to strive for greater uniformity as well as fixing the bug in
 this ticket.

 By the way, is there a discussion anywhere of why the [0.0,1.0) semi-
 closed range was chosen?  Specifically it seems a bit odd in contrast with
 randomR which is inclusive (well, optionally).  Yet it's true that Python
 and Java both use [0.0,1.0) so maybe this is standard.

 Related: the following unpublished paper discusses an interesting way of
 generating all possible float representations with uniform probability.
 Something to think about:
    http://allendowney.com/research/rand/downey07randfloat.pdf

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



More information about the Glasgow-haskell-bugs mailing list