1{-# LANGUAGE NoImplicitPrelude #-}
3 Module : Text.Pandoc.UUID
4 Copyright : Copyright (C) 2010-2019 John MacFarlane
5 License : GNU GPL, version 2 or above
7 Maintainer : John MacFarlane <jgm@berkeley.edu>
11UUID generation using Version 4 (random method) described
12in RFC4122. See http://tools.ietf.org/html/rfc4122
15module Text.Pandoc.UUID ( UUID(..), getRandomUUID, getUUID ) where
18import Data.Bits (clearBit, setBit)
20import System.Random (RandomGen, getStdGen, randoms)
21import Text.Printf (printf)
23data UUID = UUID Word8 Word8 Word8 Word8 Word8 Word8 Word8 Word8
24 Word8 Word8 Word8 Word8 Word8 Word8 Word8 Word8
26instance Show UUID where
27 show (UUID a b c d e f g h i j k l m n o p) =
50getUUID :: RandomGen g => g -> UUID
52 case take 16 (randoms gen :: [Word8]) of
53 [a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p] ->
55 let i' = i `setBit` 7 `clearBit` 6
56 -- set version (0100 for random)
57 g' = g `clearBit` 7 `setBit` 6 `clearBit` 5 `clearBit` 4
58 in UUID a b c d e f g' h i' j k l m n o p
59 _ -> error "not enough random numbers for UUID" -- should not happen
61getRandomUUID :: IO UUID
62getRandomUUID = getUUID <$> getStdGen
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