@@ -72,7 +72,12 @@ import qualified Data.Text.Encoding as T
73import Data.UUID.Types.Internal.Builder
73import Data.UUID.Types.Internal.Builder
75+#if MIN_VERSION_random(1,2,0)
76+import System.Random (Random (..), uniform)
77+import System.Random.Stateful (Uniform (..), uniformWord64)
75−import System.Random
79+import System.Random (Random (..), next)
78-- | Type representing <https://en.wikipedia.org/wiki/UUID Universally Unique Identifiers (UUID)> as specified in
83-- | Type representing <https://en.wikipedia.org/wiki/UUID Universally Unique Identifiers (UUID)> as specified in
@@ -480,6 +485,18 @@ fromLazyASCIIBytes bs =
481-- | This 'Random' instance produces __insecure__ version 4 UUIDs as
486-- | This 'Random' instance produces __insecure__ version 4 UUIDs as
482-- specified in <http://tools.ietf.org/html/rfc4122 RFC 4122>.
487-- specified in <http://tools.ietf.org/html/rfc4122 RFC 4122>.
488+#if MIN_VERSION_random(1,2,0)
489+instance Random UUID where
491+ randomR _ = random -- range is ignored
494+instance Uniform UUID where
496+ w0 <- uniformWord64 gen
497+ w1 <- uniformWord64 gen
498+ pure $ buildFromBytes 4 /-/ w0 /-/ w1
483instance Random UUID where
500instance Random UUID where
484 random g = (fromGenNext w0 w1 w2 w3 w4, g4)
501 random g = (fromGenNext w0 w1 w2 w3 w4, g4)
485 where (w0, g0) = next g
502 where (w0, g0) = next g
@@ -501,6 +518,7 @@ fromGenNext w0 w1 w2 w3 w4 =
501 -- field will "cover" the upper, non-random bits
518 -- field will "cover" the upper, non-random bits
502 /-/ (ThreeByte w3)
519 /-/ (ThreeByte w3)
503 /-/ (ThreeByte w4)
520 /-/ (ThreeByte w4)
505-- |A ByteSource to extract only three bytes from an Int, since next on StdGet
523-- |A ByteSource to extract only three bytes from an Int, since next on StdGet
506-- only returns 31 bits of randomness.
524-- only returns 31 bits of randomness.