2 Module : Text.Pandoc.UUID
3 Copyright : Copyright (C) 2010-2020 John MacFarlane
4 License : GNU GPL, version 2 or above
6 Maintainer : John MacFarlane <jgm@berkeley.edu>
10UUID generation using Version 4 (random method) described
11in RFC4122. See http://tools.ietf.org/html/rfc4122
14module Text.Pandoc.UUID ( UUID(..), getRandomUUID ) where
16import Data.Bits (clearBit, setBit)
18import System.Random (RandomGen, randoms)
19import Text.Printf (printf)
20import Text.Pandoc.Class.PandocMonad
22data UUID = UUID Word8 Word8 Word8 Word8 Word8 Word8 Word8 Word8
23 Word8 Word8 Word8 Word8 Word8 Word8 Word8 Word8
25instance Show UUID where
26 show (UUID a b c d e f g h i j k l m n o p) =
49getUUID :: RandomGen g => g -> UUID
51 case take 16 (randoms gen :: [Word8]) of
52 [a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p] ->
54 let i' = i `setBit` 7 `clearBit` 6
55 -- set version (0100 for random)
56 g' = g `clearBit` 7 `setBit` 6 `clearBit` 5 `clearBit` 4
57 in UUID a b c d e f g' h i' j k l m n o p
58 _ -> error "not enough random numbers for UUID" -- should not happen
60getRandomUUID :: PandocMonad m => m UUID
61getRandomUUID = getUUID <$> newStdGen
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list