packages feed

random-bytestring 0.0.1 → 0.1.0

raw patch · 3 files changed

+34/−10 lines, 3 files

Files

CHANGELOG.md view
@@ -1,3 +1,9 @@+0.1.0+=====++*   In the implementation of `random`, use `withSystemGen` that seeds the PRNG+    from the system randomness source.+ 0.0.1 ===== 
random-bytestring.cabal view
@@ -1,5 +1,5 @@ Name: random-bytestring-Version: 0.0.1+Version: 0.1.0 Synopsis: Efficient generation of random bytestrings Description:     Efficient generation of random bytestrings@@ -84,7 +84,7 @@      other-modules:         Benchmarks,-        Implementations +        Implementations  Benchmark eventlog-compare     default-language: Haskell2010@@ -105,4 +105,4 @@         random >= 1.1     other-modules:         Benchmarks,-        Implementations +        Implementations
src/Data/ByteString/Random.hs view
@@ -8,7 +8,6 @@ -- License: MIT -- Maintainer: lakuhtz@gmail.com -- Stability: experimental--- -- -------------------------------------------------------------------------- --  module Data.ByteString.Random@@ -28,14 +27,33 @@  import Numeric.Natural (Natural) -import System.Random.MWC (uniform, GenIO, create)+import System.Random.MWC (uniform, GenIO, withSystemRandom) -random ∷ Natural → IO ByteString-random n = do-    gen ← create-    randomGen gen n+-- $setup+-- >>> import qualified Data.ByteString as B+-- >>> import Test.QuickCheck -randomGen ∷ GenIO → Natural → IO ByteString+-- | Generate a random bytestring of length n. The PRNG is seeded+-- from the system randomness source.+--+-- prop> ioProperty $ ((fromIntegral n ===) . B.length) <$> random n+-- prop> n > 4 ==> ioProperty $ (/=) <$> random n <*> random n+--+random+    ∷ Natural+        -- ^ Length of the result bytestring in bytes+    → IO ByteString+random n = withSystemRandom $ \gen → randomGen gen n++-- | Generate a random bytestring of length n using the given+-- PRNG.+--+randomGen+    ∷ GenIO+        -- ^ A PRNG that is used to generate random bytes.+    → Natural+        -- ^ Length of the result bytestring in bytes+    → IO ByteString randomGen gen n =     bracketOnError (mallocBytes len8) free $ \ptr@(Ptr !addr) → do         {-# SCC "go" #-} go ptr