aboutsummaryrefslogtreecommitdiffstats
path: root/src/Verismith/Utils.hs
diff options
context:
space:
mode:
authorYann Herklotz <git@yannherklotz.com>2020-04-07 15:11:51 +0100
committerYann Herklotz <git@yannherklotz.com>2020-04-07 15:11:51 +0100
commit4a3f2b3448851fe9ac017ff397f9b9ae2babdce3 (patch)
treeabf392585210eee89691ebcbc135dce1ca93e51b /src/Verismith/Utils.hs
parenta6cf1079e40061196d84cfc186857f379249db2c (diff)
downloadverismith-4a3f2b3448851fe9ac017ff397f9b9ae2babdce3.tar.gz
verismith-4a3f2b3448851fe9ac017ff397f9b9ae2babdce3.zip
Remove DRBG dependency
Diffstat (limited to 'src/Verismith/Utils.hs')
-rw-r--r--src/Verismith/Utils.hs29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/Verismith/Utils.hs b/src/Verismith/Utils.hs
new file mode 100644
index 0000000..1f5dd01
--- /dev/null
+++ b/src/Verismith/Utils.hs
@@ -0,0 +1,29 @@
+{-|
+Module : Verismith
+Description : Verismith
+Copyright : (c) 2020, Yann Herklotz
+License : GPL-3
+Maintainer : yann [at] yannherklotz [dot] com
+Stability : experimental
+Portability : POSIX
+-}
+
+module Verismith.Utils
+ (generateByteString)
+where
+
+import System.Random (mkStdGen, newStdGen, randoms)
+import Data.ByteString (ByteString, pack)
+
+generateByteString :: (Maybe Int) -> Int -> Int -> IO [ByteString]
+generateByteString mseed size n = do
+ fmap pack . chunksOf size . take (size * n) . randoms <$>
+ case mseed of
+ Just seed' -> return $ mkStdGen seed'
+ Nothing -> newStdGen
+ where
+ chunksOf i _ | i <= 0 = error $ "chunksOf, number must be positive, got " ++ show i
+ chunksOf i xs = repeatedly (splitAt i) xs
+ repeatedly _ [] = []
+ repeatedly f as = b : repeatedly f as'
+ where (b, as') = f as