packages feed

Random123 0.1.1 → 0.1.2

raw patch · 2 files changed

+11/−11 lines, 2 files

Files

Random123.cabal view
@@ -1,5 +1,5 @@ Name:                Random123-Version:             0.1.1+Version:             0.1.2 Synopsis:            Haskell port of Random123 library Description:   This is a Haskell port of counter-based random number generators from the Random123 library@@ -29,7 +29,7 @@ Source-repository this   type:     git   location: http://github.com/Manticore/haskell-random123.git-  tag:      0.1.1+  tag:      0.1.2  Library   Exposed-modules:
System/Random/Random123/Threefry.hs view
@@ -92,17 +92,17 @@ -- S-box  -- FIXME: For some reason, if I do not force strictness in x0 and x1 here, it eats up the stack.-sbox' :: Bits a => Int -> (a -> RotationConstants) -> Array2 a -> Array2 a+sbox' :: (Num a, Bits a) => Int -> (a -> RotationConstants) -> Array2 a -> Array2 a sbox' r r_constant (!x0, !x1) = (x0', x1') where     rot = getRotationConstant (r_constant (undefined :: a)) (r `mod` 8)     x0' = x0 + x1     x1' = x0' `xor` (x1 `rotate` rot) -sbox2 :: (ThreefryWord a, Bits a) => Int -> Array2 a -> Array2 a+sbox2 :: (ThreefryWord a, Bits a, Num a) => Int -> Array2 a -> Array2 a sbox2 r = sbox' r rotationConstant2  -- FIXME: For some reason, if I do not force strictness in x0-x3 here, it eats up the stack.-sbox4 :: (ThreefryWord a, Bits a) => Int -> Array4 a -> Array4 a+sbox4 :: (ThreefryWord a, Bits a, Num a) => Int -> Array4 a -> Array4 a sbox4 r (!x0, !x1, !x2, !x3) = (x0', x1', x2', x3') where     (xa, xb) = if r `mod` 2 == 0 then (x1, x3) else (x3, x1)     (x0', xa') = sbox' r rotationConstant4_0 (x0, xa)@@ -136,12 +136,12 @@ addTuple4 :: Num a => Array4 a -> Array4 a -> Array4 a addTuple4 (k0, k1, k2, k3) (x0, x1, x2, x3) = (k0 + x0, k1 + x1, k2 + x2, k3 + x3) -pbox2 :: Bits a => (a, a, a) -> Int -> Array2 a -> Array2 a+pbox2 :: (Num a, Bits a) => (a, a, a) -> Int -> Array2 a -> Array2 a pbox2 extended_key r x = (x0', x1' + fromIntegral tshift) where     tshift = r `div` 4 + 1     (x0', x1') = addTuple2 x (shiftTuple2 tshift extended_key) -pbox4 :: Bits a => (a, a, a, a, a) -> Int -> Array4 a -> Array4 a+pbox4 :: (Num a, Bits a) => (a, a, a, a, a) -> Int -> Array4 a -> Array4 a pbox4 extended_key r x = (x0', x1', x2', x3' + fromIntegral tshift) where     tshift = r `div` 4 + 1     (x0', x1', x2', x3') = addTuple4 x (shiftTuple4 tshift extended_key)@@ -162,7 +162,7 @@   -- | Generates a Threefry-2 random number with a custom number of rounds.-threefry2R :: (ThreefryWord a, Bits a)+threefry2R :: (ThreefryWord a, Bits a, Num a)     => Int -- ^ number of rounds (1-32),     -> Array2 a -- ^ key,     -> Array2 a -- ^ counter,@@ -176,7 +176,7 @@   -- | Generates a Threefry-4 random number with a custom number of rounds.-threefry4R :: (ThreefryWord a, Bits a)+threefry4R :: (ThreefryWord a, Bits a, Num a)     => Int -- ^ number of rounds (1-72),     -> Array4 a -- ^ key,     -> Array4 a -- ^ counter,@@ -190,7 +190,7 @@   -- | Generates a Threefry-2 random number with the optimal number of rounds.-threefry2 :: (ThreefryWord a, Bits a)+threefry2 :: (ThreefryWord a, Bits a, Num a)     => Array2 a -- ^ key,     -> Array2 a -- ^ counter,     -> Array2 a -- ^ random number.@@ -198,7 +198,7 @@   -- | Generates a Threefry-4 random number with the optimal number of rounds.-threefry4 :: (ThreefryWord a, Bits a)+threefry4 :: (ThreefryWord a, Bits a, Num a)     => Array4 a -- ^ key,     -> Array4 a -- ^ counter,     -> Array4 a -- ^ random number.