X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=System%2FRandom.hs;h=8b648a73654a2b1087e54b985dece207be395de1;hb=55e005f94bad67200c75043c426ff51448d70431;hp=8bf81f6c853b3045b18a3a202ce52827fd7be7f1;hpb=d71fa8083f14c5eb45d2b0dc85daaf9bbac5d73c;p=haskell-directory.git diff --git a/System/Random.hs b/System/Random.hs index 8bf81f6..8b648a7 100644 --- a/System/Random.hs +++ b/System/Random.hs @@ -70,6 +70,7 @@ import Prelude #ifdef __NHC__ import CPUTime ( getCPUTime ) import Foreign.Ptr ( Ptr, nullPtr ) +import Foreign.C ( CTime, CUInt ) #else import System.CPUTime ( getCPUTime ) import System.Time ( getClockTime, ClockTime(..) ) @@ -84,13 +85,15 @@ import Numeric ( readDec ) -- replacement here. #ifdef __NHC__ data ClockTime = TOD Integer () -foreign import ccall "time.h time" readtime :: Ptr () -> IO Int +foreign import ccall "time.h time" readtime :: Ptr CTime -> IO CTime getClockTime :: IO ClockTime -getClockTime = do t <- readtime nullPtr; return (TOD (toInteger t) ()) +getClockTime = do CTime t <- readtime nullPtr; return (TOD (toInteger t) ()) #endif -- | The class 'RandomGen' provides a common interface to random number -- generators. +-- +-- Minimal complete definition: 'next' and 'split'. class RandomGen g where @@ -114,7 +117,7 @@ class RandomGen g where -- -- * If @(a,b) = 'genRange' g@, then @a < b@. -- - -- * 'genRange' is not strict. + -- * 'genRange' always returns a pair of defined 'Int's. -- -- The second condition ensures that 'genRange' cannot examine its -- argument, and hence the value it returns can be determined only by the @@ -122,6 +125,8 @@ class RandomGen g where -- a single call to 'genRange' to establish a generator's range, without -- being concerned that the generator returned by (say) 'next' might have -- a different range to the generator passed to 'next'. + -- + -- The default definition spans the full range of 'Int'. genRange :: g -> (Int,Int) -- default method