on master help sign in
Use `cryptonite` to implement `V4.nextRandom`.

Fixes #15.

commitbd60ffec647a3b446c87f79452deea4a1221442b authorAntoine Latter <aslatter@gmail.com> dateSat 2 Apr 2016, 14:28 (11 years ago) parenta594227
1 file changed+9−3
uuid/Data/UUID/V4.hs+9−3
uuid/Data/UUID/V4.hs+9−3
@@ -1,6 +1,6 @@
11{- |
22 Module : Data.UUID.V4
3− Copyright : (c) 2012 Antoine Latter
3+ Copyright : (c) 2012-2016 Antoine Latter
44
55 License : BSD-style
66
@@ -21,8 +21,14 @@
2121module Data.UUID.V4 (nextRandom) where
2222
2323import Data.UUID
24−import qualified System.Random as R
24+import Data.UUID.Types.Internal ( buildFromBytes )
25+
26+import Crypto.Random.Entropy ( getEntropy )
27+import Data.ByteString ( unpack )
2528
2629-- | Generate a random UUID. Introduced in version 1.2.6.
2730nextRandom :: IO UUID
28−nextRandom = R.randomIO
31+nextRandom = do
32+ [b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, ba, bb, bc, bd, be, bf]
33+ <- unpack `fmap` getEntropy 16
34+ return $ buildFromBytes 4 b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 ba bb bc bd be bf