@@ -29,13 +29,12 @@ UUID generation using Version 4 (random method) described
29in RFC4122. See http://tools.ietf.org/html/rfc4122
29in RFC4122. See http://tools.ietf.org/html/rfc4122
32−module Text.Pandoc.UUID ( UUID(..), getRandomUUID ) where
32+module Text.Pandoc.UUID ( UUID(..), getRandomUUID, getUUID ) where
34import Text.Printf ( printf )
34import Text.Printf ( printf )
35−import System.Random ( randomIO )
35+import System.Random ( RandomGen, randoms, getStdGen )
36import Data.Word
36import Data.Word
37import Data.Bits ( setBit, clearBit )
37import Data.Bits ( setBit, clearBit )
38−import Control.Monad ( liftM )
40data UUID = UUID Word8 Word8 Word8 Word8 Word8 Word8 Word8 Word8
39data UUID = UUID Word8 Word8 Word8 Word8 Word8 Word8 Word8 Word8
41 Word8 Word8 Word8 Word8 Word8 Word8 Word8 Word8
40 Word8 Word8 Word8 Word8 Word8 Word8 Word8 Word8
@@ -64,14 +63,16 @@ instance Show UUID where
64 printf "%02x" o ++
63 printf "%02x" o ++
65 printf "%02x" p
64 printf "%02x" p
67−getRandomUUID :: IO UUID
66+getUUID :: RandomGen g => g -> UUID
68−getRandomUUID = do
67+getUUID gen =
69− let getRN :: a -> IO Word8
70− getRN _ = liftM fromIntegral (randomIO :: IO Int)
71− [a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p] <- mapM getRN ([1..16] :: [Int])
68+ let [a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p] = take 16 $ randoms gen :: [Word8]
72 -- set variant
69 -- set variant
73− let i' = i `setBit` 7 `clearBit` 6
70+ i' = i `setBit` 7 `clearBit` 6
74 -- set version (0100 for random)
71 -- set version (0100 for random)
75− let g' = g `clearBit` 7 `setBit` 6 `clearBit` 5 `clearBit` 4
72+ g' = g `clearBit` 7 `setBit` 6 `clearBit` 5 `clearBit` 4
76− return $ UUID a b c d e f g' h i' j k l m n o p
74+ UUID a b c d e f g' h i' j k l m n o p
76+getRandomUUID :: IO UUID
77+getRandomUUID = getUUID <$> getStdGen