summaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/UUID.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Text/Pandoc/UUID.hs')
-rw-r--r--src/Text/Pandoc/UUID.hs30
1 files changed, 15 insertions, 15 deletions
diff --git a/src/Text/Pandoc/UUID.hs b/src/Text/Pandoc/UUID.hs
index 5d05fa303..4d99324db 100644
--- a/src/Text/Pandoc/UUID.hs
+++ b/src/Text/Pandoc/UUID.hs
@@ -1,5 +1,5 @@
{-
-Copyright (C) 2010-2016 John MacFarlane <jgm@berkeley.edu>
+Copyright (C) 2010-2018 John MacFarlane <jgm@berkeley.edu>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -18,7 +18,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
{- |
Module : Text.Pandoc.UUID
- Copyright : Copyright (C) 2010-2016 John MacFarlane
+ Copyright : Copyright (C) 2010-2018 John MacFarlane
License : GNU GPL, version 2 or above
Maintainer : John MacFarlane <jgm@berkeley.edu>
@@ -29,13 +29,12 @@ UUID generation using Version 4 (random method) described
in RFC4122. See http://tools.ietf.org/html/rfc4122
-}
-module Text.Pandoc.UUID ( UUID, getRandomUUID ) where
+module Text.Pandoc.UUID ( UUID(..), getRandomUUID, getUUID ) where
-import Text.Printf ( printf )
-import System.Random ( randomIO )
+import Data.Bits (clearBit, setBit)
import Data.Word
-import Data.Bits ( setBit, clearBit )
-import Control.Monad ( liftM )
+import System.Random (RandomGen, getStdGen, randoms)
+import Text.Printf (printf)
data UUID = UUID Word8 Word8 Word8 Word8 Word8 Word8 Word8 Word8
Word8 Word8 Word8 Word8 Word8 Word8 Word8 Word8
@@ -64,14 +63,15 @@ instance Show UUID where
printf "%02x" o ++
printf "%02x" p
-getRandomUUID :: IO UUID
-getRandomUUID = do
- let getRN :: a -> IO Word8
- getRN _ = liftM fromIntegral (randomIO :: IO Int)
- [a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p] <- mapM getRN ([1..16] :: [Int])
+getUUID :: RandomGen g => g -> UUID
+getUUID gen =
+ let [a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p] = take 16 $ randoms gen :: [Word8]
-- set variant
- let i' = i `setBit` 7 `clearBit` 6
+ i' = i `setBit` 7 `clearBit` 6
-- set version (0100 for random)
- let g' = g `clearBit` 7 `setBit` 6 `clearBit` 5 `clearBit` 4
- return $ UUID a b c d e f g' h i' j k l m n o p
+ g' = g `clearBit` 7 `setBit` 6 `clearBit` 5 `clearBit` 4
+ in
+ UUID a b c d e f g' h i' j k l m n o p
+getRandomUUID :: IO UUID
+getRandomUUID = getUUID <$> getStdGen