[GHC] #5133: Random instance for Float can generate values out of requested range
GHC
cvs-ghc at haskell.org
Sat Jun 25 04:56:26 CEST 2011
#5133: Random instance for Float can generate values out of requested range
---------------------------------+------------------------------------------
Reporter: richardsenington | Owner: rrnewton
Type: bug | Status: merge
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):
> In my humble opinion, the cleanest solution would be to determine how
many fraction bits we need (e.g. Float -> 23, Double -> 52). Then we can
generate a random number of the appropriate range, which maps 1:1 to a
floating-point representation. Not *all* possible floating point
representations, obviously, but at least it would be fast, uniform and in
the [0, 1) range.
I agree and that's what I implemented in revision 4cfc44a16bd9. It is
indeed faster -- 150 times faster on my machine: 11M floats a second vs
70K! I'd like to hear if others get the same results.
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/5133#comment:11>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the Glasgow-haskell-bugs
mailing list