type instance Unsigned Int16 = Word16

type instance Unsigned Int32 = Word32

type instance Unsigned Int64 = Word64

-type instance Unsigned Int = Word

type instance Unsigned Word8 = Word8

type instance Unsigned Word16 = Word16

type instance Unsigned Word32 = Word32

type instance Unsigned Word64 = Word64

-type instance Unsigned Word = Word

+-- This is workaround for bug #25.

+-- GHC-7.6 have bug (#8072) which results in calculation of wrongs

+-- number of buckets in function `uniformRange'. Consequently unformR

+-- generates values in wrong range.

+-- Bug only affects 32-bit systems and Int/Word data types. Word32

+-- works just fine. So we set Word32 as unsigned counterpart for Int

+-- and Word on 32-bit systems. It's done only for GHC-7.6 because

+-- other versions are unaffected by the bug and we expect that GHC may

+-- optimise code which uses Word better.

+#if (WORD_SIZE_IN_BITS < 64) && (__GLASGOW_HASKELL__ == 706)

+type instance Unsigned Int = Word32

+type instance Unsigned Word = Word32

+type instance Unsigned Int = Word

+type instance Unsigned Word = Word

-- Subtract two numbers under assumption that x>=y and store result in

-- unsigned data type of same size

# System/Random/MWC/CondensedTable.hs

-- the case, this algorithm will construct a table for some

-- distribution that may bear no resemblance to what you intended.

- :: (Vector v (a,Word32), Vector v (a,Double), Vector v a, Vector v Word32~~, Show a~~)

+ :: (Vector v (a,Word32), Vector v (a,Double), Vector v a, Vector v Word32)

=> v (a, Double) -> CondensedTable v a

{-# INLINE tableFromProbabilities #-}

-- probilities. Non-positive weights are discarded, and those

-- remaining are normalized to 1.

- :: (Vector v (a,Word32), Vector v (a,Double), Vector v a, Vector v Word32~~, Show a~~)

+ :: (Vector v (a,Word32), Vector v (a,Double), Vector v a, Vector v Word32)

=> v (a, Double) -> CondensedTable v a

{-# INLINE tableFromWeights #-}

tableFromWeights = tableFromProbabilities . normalize . G.filter ((> 0) . snd)

# System/Random/MWC/Distributions.hs

+-- | Generate truncated exponentially distributed random variate.

+truncatedExp :: PrimMonad m

+ => Double -- ^ Scale parameter

+ -> (Double,Double) -- ^ Range to which distribution is

+ -- truncated. Values may be negative.

+ -> Gen (PrimState m) -- ^ Generator.

+{-# INLINE truncatedExp #-}

+truncatedExp beta (a,b) gen = do

+ -- We shift a to 0 and then generate distribution truncated to [0,b-a]

+ return $! a - log ( (1 - p) + p*exp(-beta*delta)) / beta

-- | Random variate generator for gamma distribution.

=> Double -- ^ Shape parameter