@@ -72,7 +72,12 @@ import qualified Data.Text.Encoding as T
7272
7373import Data.UUID.Types.Internal.Builder
7474
75−import System.Random
75+#if MIN_VERSION_random(1,2,0)
76+import System.Random (Random (..), uniform)
77+import System.Random.Stateful (Uniform (..), uniformWord64)
78+#else
79+import System.Random (Random (..), next)
80+#endif
7681
7782
7883-- | Type representing <https://en.wikipedia.org/wiki/UUID Universally Unique Identifiers (UUID)> as specified in
@@ -480,6 +485,18 @@ fromLazyASCIIBytes bs =
480485
481486-- | This 'Random' instance produces __insecure__ version 4 UUIDs as
482487-- specified in <http://tools.ietf.org/html/rfc4122 RFC 4122>.
488+#if MIN_VERSION_random(1,2,0)
489+instance Random UUID where
490+ random = uniform
491+ randomR _ = random -- range is ignored
492+
493+-- @since 1.0.4
494+instance Uniform UUID where
495+ uniformM gen = do
496+ w0 <- uniformWord64 gen
497+ w1 <- uniformWord64 gen
498+ pure $ buildFromBytes 4 /-/ w0 /-/ w1
499+#else
483500instance Random UUID where
484501 random g = (fromGenNext w0 w1 w2 w3 w4, g4)
485502 where (w0, g0) = next g
@@ -501,6 +518,7 @@ fromGenNext w0 w1 w2 w3 w4 =
501518 -- field will "cover" the upper, non-random bits
502519 /-/ (ThreeByte w3)
503520 /-/ (ThreeByte w4)
521+#endif
504522
505523-- |A ByteSource to extract only three bytes from an Int, since next on StdGet
506524-- only returns 31 bits of randomness.