h*GQ      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~1.3.0(c) Alexey Kuleshevich 2024;BSD-style (see the file LICENSE in the 'random' repository)libraries@haskell.org Trustworthy randomConvert a ShortByteString to ByteString by casting, whenever memory is pinned, otherwise make a copy into a new pinned ByteStringrandomWrite contents of the list into the mutable array. Make sure that array is big enough or segfault will happen.randomGenerate a list of indices that will be used for swapping elements in uniform shuffling: [ (0, n - 1) , (0, n - 2) , (0, n - 3) , ... , (0, 3) , (0, 2) , (0, 1) ] randomImplementation of mutable version of Fisher-Yates shuffle. Unfortunately, we cannot generally interleave pseudo-random number generation and mutation of  monad, therefore we have to pre-generate all of the index swaps with  and store them in a list before we can perform the actual swaps.random+This is a ~x2-x3 more efficient version of . It is more efficient because it does not need to pregenerate a list of indices and instead generates them on demand. Because of this the result that will be produced will differ for the same generator, since the order in which index swaps are generated is reversed.;Unfortunately, most stateful generator monads can't handle , so this version is only used for implementing the pure shuffle.random3Offset into immutable byte array in number of bytesrandom3Offset into immutable byte array in number of bytesrandom"Starting offset in number of bytesrandom Ending offset in number of bytesrandom1Offset into mutable byte array in number of bytesrandom48 bytes that will be written into the supplied arrayrandom3Action that generates a Word in the supplied range.random"Number of index swaps to generate.(c) Andrew Lelechenko 2020;BSD-style (see the file LICENSE in the 'random' repository)libraries@haskell.org Safe-Inferred=[randomA type class for data with a finite number of inhabitants. This type class is used in the default implementation of .-Users are not supposed to write instances of : manually. There is a default implementation in terms of  instead.&:seti -XDeriveGeneric -XDeriveAnyClassimport GHC.Generics (Generic)9data MyBool = MyTrue | MyFalse deriving (Generic, Finite)data Action = Code MyBool | Eat (Maybe Bool) | Sleep deriving (Generic, Finite)randomCardinality of a set.random%Shift n is equivalent to Card (bit n)random'This is needed only as a superclass of .random'This is needed only as a superclass of . "(c) The University of Glasgow 2001;BSD-style (see the file LICENSE in the 'random' repository)libraries@haskell.orgstable Trustworthy  =\randomThe class of types for which a uniformly distributed value can be drawn from a range.randomGenerates a value uniformly distributed over the provided range, which is interpreted as inclusive in the lower and upper bound.uniformRM (1 :: Int, 4 :: Int). generates values uniformly from the set  \{1,2,3,4\}"uniformRM (1 :: Float, 4 :: Float). generates values uniformly from the set \{x\;|\;1 \le x \le 4\}The following law should hold to make the function always defined: #uniformRM (a, b) = uniformRM (b, a)/The range is understood as defined by means of , so 6isInRange (a, b) <$> uniformRM (a, b) gen == pure Truebut beware of  %System-Random-Stateful.html#fpcaveatsfloating point number caveats.&There is a default implementation via :&:seti -XDeriveGeneric -XDeriveAnyClassimport GHC.Generics (Generic)import Data.Word (Word8)!import Control.Monad (replicateM)import System.Random.Statefulgen <- newIOGenM (mkStdGen 42)data Tuple = Tuple Bool Word8 deriving (Show, Generic, UniformRange)?replicateM 10 (uniformRM (Tuple False 100, Tuple True 150) gen)[Tuple False 102,Tuple True 118,Tuple False 115,Tuple True 113,Tuple True 126,Tuple False 127,Tuple True 130,Tuple False 113,Tuple False 150,Tuple False 125]random-A notion of (inclusive) ranges prescribed to a.Ranges are symmetric: ,isInRange (lo, hi) x == isInRange (hi, lo) xRanges include their endpoints: isInRange (lo, hi) lo == True/When endpoints coincide, there is nothing else: isInRange (x, x) y == x == yEndpoints are endpoints: 8isInRange (lo, hi) x ==> isInRange (lo, x) hi == x == hi Ranges are transitive relations: isInRange (lo, hi) lo' && isInRange (lo, hi) hi' && isInRange (lo', hi') x ==> isInRange (lo, hi) x%There is a default implementation of  via . Other helper function that can be used for implementing this function are > and ?randomDefault implementation of  type class for  data. It's important to use , because without it  and  remain polymorphic too long and GHC fails to inline or specialize it, ending up building full  a structure in memory.  makes  and  used in , monomorphic, so GHC is able to specialize 0 instance reasonably close to a handwritten one.randomThe class of types for which a uniformly distributed value can be drawn from all possible values of the type.randomGenerates a value uniformly distributed over all possible values of that type.&There is a default implementation via :&:seti -XDeriveGeneric -XDeriveAnyClassimport GHC.Generics (Generic)import System.Random.Statefuldata MyBool = MyTrue | MyFalse deriving (Show, Generic, Finite, Uniform)data Action = Code MyBool | Eat (Maybe Bool) | Sleep deriving (Show, Generic, Finite, Uniform)gen <- newIOGenM (mkStdGen 42)"uniformListM 10 gen :: IO [Action][Code MyTrue,Code MyTrue,Eat Nothing,Code MyFalse,Eat (Just False),Eat (Just True),Eat Nothing,Eat (Just False),Sleep,Code MyFalse]random,The standard pseudo-random number generator.randomWrapper for pure state gen, which acts as an immutable seed for the corresponding stateful generator  randomOpaque data type that carries the type of a pure pseudo-random number generator. random?Functionality for thawing frozen generators is not part of the  class, becase not all mutable generators support functionality of creating new mutable generators, which is what thawing is in its essence. For this reason  does not have an instance for this type class, but it has one for .9Here is an important law that relates this type class to 1Roundtrip and independence of mutable generators: 7traverse thawGen fgs >>= traverse freezeGen = pure fgs randomCreate a new mutable pseudo-random number generator from its frozen state.randomThis class is designed for mutable pseudo-random number generators that have a frozen imutable counterpart that can be manipulated in pure code.It also works great with frozen generators that are based on pure generators that have a  instance.=Here are a few laws, which are important for this type class:0Roundtrip and complete destruction on overwrite: -overwriteGen mg fg >> freezeGen mg = pure fg $Modification of a mutable generator: 2overwriteGen mg fg = modifyGen mg (const ((), fg)  Freezing of a mutable generator: -freezeGen mg = modifyGen mg (fg -> (fg, fg)) randomRepresents the state of the pseudo-random number generator for use with   and .randomSaves the state of the pseudo-random number generator as a frozen seed.randomApply a pure function to the frozen pseudo-random number generator.randomOverwrite contents of the mutable pseudo-random number generator with the supplied frozen onerandom< is an interface to monadic pseudo-random number generators.randomuniformWord32R upperBound g generates a / that is uniformly distributed over the range [0, upperBound].randomuniformWord64R upperBound g generates a / that is uniformly distributed over the range [0, upperBound].random Generates a / that is uniformly distributed over the entire  range.&The default implementation extracts a  from .random Generates a 0 that is uniformly distributed over the entire  range.&The default implementation extracts a  from .random Generates a 0 that is uniformly distributed over the entire  range.&The default implementation extracts a  from .random Generates a 0 that is uniformly distributed over the entire  range.(The default implementation combines two  from  into one .randomuniformByteArrayM n g generates a  of length n" filled with pseudo-random bytes.randomuniformShortByteString n g generates a  of length n" filled with pseudo-random bytes.randomPseudo-random generators that can be split into two separate and independent psuedo-random generators should provide an instance for this type class.4Historically this functionality was included in the  type class in the ) function, however, few pseudo-random generators possess this property of splittability. This lead the old )1 function being usually implemented in terms of .random5Returns two distinct pseudo-random number generators.Implementations should take care to ensure that the resulting generators are not correlated.random9 is an interface to pure pseudo-random number generators. is the standard # instance provided by this library.random Returns an ; that is uniformly distributed over the range returned by (9 (including both end points), and a new generator. Using * is inefficient as all operations go via . See  =https://alexey.kuleshevi.ch/blog/2019/12/21/random-benchmarkshere* for more details. It is thus deprecated. random Returns a / that is uniformly distributed over the entire  range.!random Returns a / that is uniformly distributed over the entire  range."random Returns a / that is uniformly distributed over the entire  range.#random Returns a / that is uniformly distributed over the entire  range.$randomgenWord32R upperBound g returns a / that is uniformly distributed over the range [0, upperBound].%randomgenWord64R upperBound g returns a / that is uniformly distributed over the range [0, upperBound].&randomSame as -  , but for .genShortByteString n g returns a  of length n" filled with pseudo-random bytes.Note - This function will be removed from the type class in the next major release as it is no longer needed because of '.'randomFill in the supplied  with uniformly generated random bytes. This function is unsafe because it is not required to do any bounds checking. For a safe variant use   instead.'Default type class implementation uses /.(random'Yields the range of values returned by .It is required that:If  (a, b) = ( g, then a < b.( must not examine its argument so the value it returns is determined only by the instance of ./The default definition spans the full range of .)random5Returns two distinct pseudo-random number generators.Implementations should take care to ensure that the resulting generators are not correlated. Some pseudo-random number generators are not splittable. In that case, the )0 implementation should fail with a descriptive  message.*randomThis is a binary form of pseudo-random number generator's state. It is designed to be safe and easy to use for input/output operations like restoring from file, transmitting over the network, etc.Constructor is not exported, becasue it is important for implementation to enforce the invariant of the underlying byte array being of the exact same length as the generator has specified in   . Use   and  1 to get access to the raw bytes in a safe manner.+randomSplits a pseudo-random number generator into two. Overwrites the mutable pseudo-random number generator with one of the immutable pseudo-random number generators produced by a ) function and returns the other.,randomSplits a pseudo-random number generator into two. Overwrites the mutable wrapper with one of the resulting generators and returns the other as a new mutable generator.-randomEfficiently generates a sequence of pseudo-random bytes in a platform independent manner..random Using an 7 action that generates 8 bytes at a time fill in a new " in architecture agnostic manner./randomEfficiently generates a sequence of pseudo-random bytes in a platform independent manner.0randomSame as 1, but runs in .1randomEfficiently fills in a new " in a platform independent manner.2randomuniformShortByteString n g generates a  of length n" filled with pseudo-random bytes.3random(Runs a monadic generating action in the 4 monad using a pure pseudo-random number generator.Examplesimport System.Random.Statefullet pureGen = mkStdGen 137,runStateGen pureGen randomM :: (Int, StdGen)(7879794327570578227,StdGen {unStdGen = SMGen 11285859549637045894 7641485672361121627})4random(Runs a monadic generating action in the  monad using a pure pseudo-random number generator. Returns only the resulting pseudo-random value.Examplesimport System.Random.Statefullet pureGen = mkStdGen 137#runStateGen_ pureGen randomM :: Int78797943275705782275random(Runs a monadic generating action in the 4 monad using a pure pseudo-random number generator.Examplesimport System.Random.Statefullet pureGen = mkStdGen 1370runStateGenT pureGen randomM :: IO (Int, StdGen)(7879794327570578227,StdGen {unStdGen = SMGen 11285859549637045894 7641485672361121627})6random(Runs a monadic generating action in the  monad using a pure pseudo-random number generator. Returns only the resulting pseudo-random value.Examplesimport System.Random.Statefullet pureGen = mkStdGen 137'runStateGenT_ pureGen randomM :: IO Int78797943275705782277random(Runs a monadic generating action in the 4 monad using a pure pseudo-random number generator.8random(Runs a monadic generating action in the = monad using a pure pseudo-random number generator. Same as 7(, but discards the resulting generator.9random)Generates a list of pseudo-random values.Examplesimport System.Random.Statefullet pureGen = mkStdGen 137g <- newIOGenM pureGenuniformListM 10 g :: IO [Bool]7[True,True,True,True,False,True,True,False,False,False]:random>Generates a list of pseudo-random values in a specified range.Examplesimport System.Random.Statefullet pureGen = mkStdGen 137g <- newIOGenM pureGen'uniformListRM 10 (20, 30) g :: IO [Int][23,21,28,25,28,28,26,25,29,27];random Constructs a  deterministically from an  seed. See < for a ( variant that is architecture agnostic.<random Constructs a  deterministically from a  seed.The difference between ; is that < will work the same on 64-bit and 32-bit architectures, while the former can only use 32-bit of information for initializing the psuedo-random number generator on 32-bit operating systemsrandomGlobal mutable veriable with =randomA definition of  for 0 types. If your data has several fields of sub- cardinality, this instance may be more efficient than one, derived via  and .&:seti -XDeriveGeneric -XDeriveAnyClassimport GHC.Generics (Generic)import System.Random.Statefuldata Triple = Triple Word8 Word8 Word8 deriving (Show, Generic, Finite):instance Uniform Triple where uniformM = uniformViaFiniteMgen <- newIOGenM (mkStdGen 42)!uniformListM 5 gen :: IO [Triple][Triple 60 226 48,Triple 234 194 151,Triple 112 96 95,Triple 51 251 15,Triple 6 0 208]>randomUtilize  instance to decide if a value is within the range. Designed to be used for implementing ?randomUtilize  instance to decide if a value is within the range. Designed to be used for implementing @randomArchitecture specific ( generation in the specified lower rangeArandom Generates uniformly distributed  in the range [0, 1]1. Numbers are generated by generating uniform  and dividing it by 2^{64}. It's used to implement  instance for .Brandom Generates uniformly distributed  in the range (0, 1]. Number is generated as )2^{-64}/2+\operatorname{uniformDouble01M}. Constant is 1/2 of smallest nonzero value which could be generated by A.CrandomThis is the function that is used to scale a floating point value from random word range to the custom  [low, high] range.Drandom Generates uniformly distributed  in the range [0, 1]1. Numbers are generated by generating uniform  and dividing it by 2^{32}. It's used to implement  instance for .Erandom Generates uniformly distributed  in the range (0, 1]. Number is generated as (2^{-32}/2+\operatorname{uniformFloat01M}. Constant is 1/2 of smallest nonzero value which could be generated by D.Frandom Generates uniformly distributed . One can use it to define a  instance: data Colors = Red | Green | Blue deriving (Enum, Bounded) instance Uniform Colors where uniformM = uniformEnumMGrandom Generates uniformly distributed 1 in the given range. One can use it to define a  instance: data Colors = Red | Green | Blue deriving (Enum) instance UniformRange Colors where uniformRM = uniformEnumRM inInRange (lo, hi) x = isInRange (fromEnum lo, fromEnum hi) (fromEnum x)random"Generate an integral in the range [l, h] if l <= h and [h, l] otherwise.random"Generate an integral in the range [0, s)4 using a variant of Lemire's multiplication method.Daniel Lemire. 2019. Fast Random Integer Generation in an Interval. In ACM Transactions on Modeling and Computer Simulation https://doi.org/10.1145/3230636PRECONDITION (unchecked): s > 0randomboundedByPowerOf2ExclusiveIntegralM s ~ boundedExclusiveIntegralM (bit s)randomintegralWordSize i returns that least w such that i <= WORD_SIZE_IN_BITS^w.randomuniformIntegralWords n5 is a uniformly pseudo-random integral in the range [0, WORD_SIZE_IN_BITS^n).randomUniformly generate an ! in an inclusive-inclusive range.:Only use for integrals size less than or equal to that of .randomUniformly generate Word32 in [0, s].randomSee  $https://arxiv.org/pdf/1805.10941.pdfLemire's paper,  3https://www.pcg-random.org/posts/bounded-rands.htmlO'Neill's blogpost and more directly  https://github.com/imneme/bounded-rands/blob/3d71f53c975b1e5b29f2f3b05a74e26dab9c3d84/bounded32.cpp#L234O'Neill's github repo). N.B. The range is [0,r) **not** [0,r].random&This only works for unsigned integralsrandomThis works for signed integrals by explicit conversion to unsigned and abusing overflow. It uses , therefore it requires functions that take the value to unsigned and back.randomDetailed explanation about the algorithm employed here can be found in this post: http://web.archive.org/web/20200520071940/https://www.pcg-random.org/posts/bounded-rands.htmlrandomSee  %System-Random-Stateful.html#fpcaveatsFloating point number caveats.randomSee  %System-Random-Stateful.html#fpcaveatsFloating point number caveats.randomSee  %System-Random-Stateful.html#fpcaveatsFloating point number caveats.randomSee  %System-Random-Stateful.html#fpcaveatsFloating point number caveats.randomShould % be allocated as pinned memory or notrandomSize of the newly created  in number of bytes.random2Generator to use for filling in the newly created 'random'Mutable array to fill with random bytesrandomOffset into a mutable array from the beginning in number of bytes. Offset must be non-negative, but this will not be checkedrandomNumber of randomly generated bytes to write into the array. Number of bytes must be non-negative and less then the total size of the array, minus the offset. This also will be checked.-random;Should byte array be allocted in pinned or unpinned memory.randomNumber of bytes to generaterandom"Pure pseudo-random numer generator/randomStarting offsetrandom.Number of random bytes to write into the arrayrandom4ST action that can generate 8 random bytes at a time1randomNumber of bytes to generaterandom4IO action that can generate 8 random bytes at a time@randomMaximum value to generaterandomStateful generatorCrandomLowrandomHighrandomUniformly distributed unsigned integral value that will be used for converting to a floating point value and subsequent scaling to the specified rangerandomConvert signed to unsigned. a and b must be of the same size.randomConvert unsigned to signed. a and b must be of the same size.randomRange.random Generator.) !"#$%'&(* +,;< 345678=@ABDEFG9:>?C2-.10/ (c) Alexey Kuleshevich 2024;BSD-style (see the file LICENSE in the 'random' repository)libraries@haskell.org Trustworthy1q`HrandomInterface for converting a pure pseudo-random number generator to and from non-empty sequence of bytes. Seeds are stored in Little-Endian order regardless of the platform it is being used on, which provides cross-platform compatibility, while providing optimal performance for the most common platform type.Conversion to and from a * serves as a building block for implementing serialization for any pure or frozen pseudo-random number generator.It is not trivial to implement platform independence. For this reason this type class has two alternative ways of creating an instance for this class. The easiest way for constructing a platform indepent seed is by converting the inner state of a generator to and from a list of 64 bit words using M and L respectively. In that case cross-platform support will be handled automaticaly.:set -XDataKinds -XTypeFamilies import Data.Word (Word8, Word32)(import Data.Bits ((.|.), shiftR, shiftL)+import Data.List.NonEmpty (NonEmpty ((:|)))9data FiveByteGen = FiveByteGen Word8 Word32 deriving Show:{"instance SeedGen FiveByteGen where type SeedSize FiveByteGen = 5 fromSeed64 (w64 :| _) = FiveByteGen (fromIntegral (w64 `shiftR` 32)) (fromIntegral w64) toSeed64 (FiveByteGen x1 x4) =? let w64 = (fromIntegral x1 `shiftL` 32) .|. fromIntegral x4 in (w64 :| []):}FiveByteGen 0x80 0x01020304FiveByteGen 128 16909060/fromSeed (toSeed (FiveByteGen 0x80 0x01020304))FiveByteGen 128 16909060$toSeed (FiveByteGen 0x80 0x01020304)#Seed [0x04, 0x03, 0x02, 0x01, 0x80]&toSeed64 (FiveByteGen 0x80 0x01020304)549772722948 :| []However, when performance is of utmost importance or default handling of cross platform independence is not sufficient, then an adventurous developer can try implementing conversion into bytes directly with K and J.Properties that must hold: > fromSeed (toSeed gen) == gen  #> fromSeed64 (toSeed64 gen) == gen -Note, that there is no requirement for every *8 to roundtrip, eg. this proprty does not even hold for :;let seed = nonEmptyToSeed (0xab :| [0xff00]) :: Seed StdGenseed == toSeed (fromSeed seed)FalseIrandomNumber of bytes that is required for storing the full state of a pseudo-random number generator. It should be big enough to satisfy the roundtrip property: > fromSeed (toSeed gen) == gen JrandomConvert from a binary representation to a pseudo-random number generatorKrandomConvert to a binary representation of a pseudo-random number generatorLrandomConstruct pseudo-random number generator from a list of words. Whenever list does not have enough bytes to satisfy the I requirement, it will be padded with zeros. On the other hand when it has more than necessary, extra bytes will be dropped.For example if I is set to 2, then only the lower 16 bits of the first element in the list will be used.Mrandom9Convert pseudo-random number generator to a list of words In case when I is not a multiple of 8, then the upper bits of the last word in the list will be set to zero.NrandomGet the expected size of the * in number bytesOrandom Just like N+, except it accepts a proxy as an argument.Prandom Construct a * from a  of expected length. Whenever  does not match the I? specified by the pseudo-random generator, this function will .Qrandom:Helper function that allows for operating directly on the *, while supplying a function that uses the pseudo-random number generator that is constructed from that *.Example:set -XTypeApplicationsimport System.RandomwithSeed (nonEmptyToSeed (pure 2024) :: Seed StdGen) (uniform @Int)(1039666877624726199,Seed [0xe9, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])RrandomSame as Q, except it is useful with monadic computation and frozen generators.See  for a helper that also handles seeds for mutable pseduo-random number generators.SrandomThis is a function that shows the name of the generator type, which is useful for error reporting.Trandom Just like P , but uses  ByteString/ as argument. Results in a memcopy of the seed.Urandom Unwrap the * and get the underlying Vrandom Just like U, but produced a  ByteString#. Results in a memcopy of the seed.WrandomRead the seed from a file and use it for constructing a pseudo-random number generator. After supplied action has been applied to the constructed generator, the resulting generator will be converted back to a seed and written to the same file.Xrandom6Construct a seed from a list of 64-bit words. At most I many bytes will be used.Yrandom Convert a * to a list of 64bit words.HIJKLM*NOPUTVQRWSXY"(c) The University of Glasgow 2001;BSD-style (see the file LICENSE in the 'random' repository)libraries@haskell.orgstable Trustworthy=#ZrandomThe class of types for which random values can be generated. Most instances of Z will produce values that are uniformly distributed on the full range, but for those types without a well-defined "full range" some sensible default subrange will be selected.Z exists primarily for backwards compatibility with version 1.1 of this library. In new code, use the better specified  and  instead.[randomTakes a range (lo,hi)' and a pseudo-random number generator g, and returns a pseudo-random value uniformly distributed over the closed interval [lo,hi], together with a new generator. It is unspecified what happens if lo>hi1, but usually the values will simply get swapped.let gen = mkStdGen 26fst $ randomR ('a', 'z') gen'z'fst $ randomR ('a', 'z') gen'z'=For continuous types there is no requirement that the values lo and hi are ever produced, but they may be, depending on the implementation and the interval.&There is no requirement to follow the Ord instance and the concept of range can be defined on per type basis. For example product types will treat their values independently:5fst $ randomR (('a', 5.0), ('z', 10.0)) $ mkStdGen 26('z',5.22694980853051)'In case when a lawful range is desired ` should be used instead.\random The same as [3, but using a default range determined by the type: For bounded types (instances of  , such as +), the range is normally the whole type.For floating point types, the range is normally the closed interval [0,1].For *, the range is (arbitrarily) the range of .]randomPlural variant of [, producing an infinite list of pseudo-random values instead of returning a new generator.^randomPlural variant of \, producing an infinite list of pseudo-random values instead of returning a new generator._randomGenerates a value uniformly distributed over all possible values of that type.This is a pure version of .Examplesimport System.Randomlet pureGen = mkStdGen 137!uniform pureGen :: (Bool, StdGen)(True,StdGen {unStdGen = SMGen 11285859549637045894 7641485672361121627})You can use type applications to disambiguate the type of the generated numbers::seti -XTypeApplicationsuniform @Bool pureGen(True,StdGen {unStdGen = SMGen 11285859549637045894 7641485672361121627})`randomGenerates a value uniformly distributed over the provided range, which is interpreted as inclusive in the lower and upper bound.uniformR (1 :: Int, 4 :: Int). generates values uniformly from the set  \{1,2,3,4\}!uniformR (1 :: Float, 4 :: Float). generates values uniformly from the set \{x\;|\;1 \le x \le 4\}The following law should hold to make the function always defined: !uniformR (a, b) = uniformR (b, a)This is a pure version of .Examplesimport System.Randomlet pureGen = mkStdGen 137%uniformR (1 :: Int, 4 :: Int) pureGen(4,StdGen {unStdGen = SMGen 11285859549637045894 7641485672361121627})You can use type applications to disambiguate the type of the generated numbers::seti -XTypeApplicationsuniformR @Int (1, 4) pureGen(4,StdGen {unStdGen = SMGen 11285859549637045894 7641485672361121627})arandomProduce an infinite list of pseudo-random values. Integrates nicely with list fusion. Naturally, there is no way to recover the final generator, therefore either use ) before calling a or use c instead. Similar to ^, except it relies on  type class instead of ZExampleslet gen = mkStdGen 2023import Data.Word (Word16)!take 5 $ uniforms gen :: [Word16][56342,15850,25292,14347,13919]brandomProduce an infinite list of pseudo-random values in a specified range. Same as a, integrates nicely with list fusion. There is no way to recover the final generator, therefore either use ) before calling b or use d instead. Similar to ], except it relies on  type class instead of Z.Exampleslet gen = mkStdGen 2023)take 5 $ uniformRs (10, 100) gen :: [Int][32,86,21,57,39]crandomProduce a list of the supplied length with elements generated uniformly.See 9 for a stateful counterpart.Exampleslet gen = mkStdGen 2023import Data.Word (Word16)'uniformList 5 gen :: ([Word16], StdGen)([56342,15850,25292,14347,13919],StdGen {unStdGen = SMGen 6446154349414395371 1920468677557965761})drandomProduce a list of the supplied length with elements generated uniformly.See 9 for a stateful counterpart.Exampleslet gen = mkStdGen 2023/uniformListR 10 (20, 30) gen :: ([Int], StdGen)([26,30,27,24,30,25,27,21,27,27],StdGen {unStdGen = SMGen 12965503083958398648 1920468677557965761})erandom7Shuffle elements of a list in a uniformly random order.Examples)uniformShuffleList "ELVIS" $ mkStdGen 252("LIVES",StdGen {unStdGen = SMGen 17676540583805057877 5302934877338729551})frandom Generates a  of the specified size using a pure pseudo-random number generator. See uniformByteStringM for the monadic version.Examplesimport System.Randomimport Data.ByteStringlet pureGen = mkStdGen 137:seti -Wno-deprecations)unpack . fst . genByteString 10 $ pureGen![51,123,251,37,49,167,90,109,1,4]grandom Generates a  of the specified size using a pure pseudo-random number generator. See uniformByteStringM for the monadic version.Examplesimport System.Randomimport Data.ByteString (unpack)let pureGen = mkStdGen 137+unpack . fst $ uniformByteString 10 pureGen![51,123,251,37,49,167,90,109,1,4]hrandomSame as -  , but for . Returns a  of length n! filled with pseudo-random bytes.Examplesimport System.Random%import Data.ByteString.Short (unpack)let pureGen = mkStdGen 1370unpack . fst $ uniformShortByteString 10 pureGen![51,123,251,37,49,167,90,109,1,4]irandomFill in a slice of a mutable byte array with randomly generated bytes. This function does not fail, instead it clamps the offset and number of bytes to generate into a valid range.random uniformRM (0, 100) g >>= flip uniformByteStringM g >>= hPutStr hand then run it:#newIOGenM (mkStdGen 1729) >>= ioGenrandomFrozen version of mutable  generatorrandom Wraps an  that holds a pure pseudo-random number generator. All operations are performed atomically.7 is safe in the presence of exceptions and concurrency. is the slowest of the monadic adapters due to the overhead of its atomic operations.randomInterface to operations on  wrappers like  and  .random7Shuffle elements of a list in a uniformly random order.Examplesimport System.Random.Stateful9runStateGen_ (mkStdGen 127) $ uniformShuffleListM "ELVIS""LIVES"random7Runs a mutable pseudo-random number generator from its  state.Examplesimport Data.Int (Int8)withMutableGen (IOGen (mkStdGen 217)) (uniformListM 5) :: IO ([Int8], IOGen StdGen)([-74,37,-50,-2,3],IOGen {unIOGen = StdGen {unStdGen = SMGen 4273268533320920145 15251669095119325999}})randomSame as ', but only returns the generated value.Examplesimport System.Random.Statefullet pureGen = mkStdGen 137withMutableGen_ (IOGen pureGen) (uniformRM (1 :: Int, 6 :: Int))4random Just like , except uses a * instead of a frozen generator.ExamplesHere is good example of how  can be used with W#, which uses a locally stored seed.First we define a  reportSeed function that will print the contents of a seed file as a list of bytes::import Data.ByteString as BS (readFile, writeFile, unpack):seti -XOverloadedStringslet reportSeed fp = print . ("Seed: " <>) . show . BS.unpack =<< BS.readFile fpGiven a file path, write an  seed into the file:.:seti -XFlexibleContexts -XScopedTypeVariableslet writeInitSeed fp = BS.writeFile fp (unSeedToByteString (toSeed (mkStdGen 2025)))Apply a  monadic action that uses  +, restored from the seed in the given path:let withMutableSeedFile fp action = withSeedFile fp (\(seed :: Seed (IOGen StdGen)) -> withSeedMutableGen seed action)Given a path and an action initialize the seed file and apply the action using that seed:let withInitSeedFile fp action = writeInitSeed fp *> reportSeed fp *> withMutableSeedFile fp action <* reportSeed fpFor the sake of example we will use a temporary directory for storing the seed. Here we report the contents of the seed file before and after we shuffle a list:3import UnliftIO.Temporary (withSystemTempDirectory)withSystemTempDirectory "random" (\fp -> withInitSeedFile (fp ++ "/seed.bin") (uniformShuffleListM [1..10]))"Seed: [183,178,143,77,132,163,109,14,157,105,82,99,148,82,109,173]""Seed: [60,105,117,203,187,138,69,39,157,105,82,99,148,82,109,173]"[7,5,4,3,1,8,10,6,9,2]random Just like , except it doesn't return the final generator, only the resulting value. This is slightly more efficient, since it doesn't incur overhead from freezeing the mutable generatorrandom applySTGen random g)) :: (Int, StdGen)(7879794327570578227,StdGen {unStdGen = SMGen 11285859549637045894 7641485672361121627})random(Runs a monadic generating action in the 4 monad using a pure pseudo-random number generator.Examplesimport System.Random.Statefullet pureGen = mkStdGen 137?(runSTGen pureGen (\g -> applySTGen random g)) :: (Int, StdGen)(7879794327570578227,StdGen {unStdGen = SMGen 11285859549637045894 7641485672361121627})random(Runs a monadic generating action in the  monad using a pure pseudo-random number generator. Returns only the resulting pseudo-random value.Examplesimport System.Random.Statefullet pureGen = mkStdGen 1376(runSTGen_ pureGen (\g -> applySTGen random g)) :: Int7879794327570578227randomCreates a new  in .randomCreates a new  in .randomApplies a pure operation to the wrapped pseudo-random number generator.Examplesimport Control.Concurrent.STMimport System.Random.Statefulimport Data.Int (Int32)let pureGen = mkStdGen 137stmGen <- newTGenMIO pureGen1atomically $ applyTGen uniform stmGen :: IO Int32 637238067randomrandom) !"#$%'&(Z\[]^*HIJKLMI_`abcde-gif;?9:2.10/ABDEFG@C) !"#$%'&(Z\[]^*HIJKLM_`abcde-gif;?9:2.10/ABDEFG@C !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVW X  Y Z [ \ ] ^ _ ` a b c d e f g hijklmnopqrstu+vwxyz{|}~:#random-1.3.0-22DArszRTrP1fxBoP3WXFX System.RandomSystem.Random.StatefulrandomSystem.Random.ArraySystem.Random.GFiniteUniformSystem.Random.InternalSystem.Random.SatefuluniformFillMutableByteArrayMSystem.Random.SeedSeedSizemkSizeunSizeFinitewithSeedMutableGenuniformM uniformRM globalStdGenapplyAtomicGenrandomRMrandomM UniformRange isInRangeStdGenStateGen unStateGen StateGenM ThawedGenthawGen FrozenGen MutableGen freezeGen modifyGen overwriteGen StatefulGenuniformWord32RuniformWord64R uniformWord8 uniformWord16 uniformWord32 uniformWord64uniformByteArrayMuniformShortByteStringSplitGensplitGen RandomGennextgenWord8 genWord16 genWord32 genWord64 genWord32R genWord64RgenShortByteString!unsafeUniformFillMutableByteArraygenRangesplitSeed splitGenMsplitMutableGenMuniformByteArrayfillByteArrayST(defaultUnsafeUniformFillMutableByteArraygenShortByteStringSTgenShortByteStringIOuniformShortByteStringM runStateGen runStateGen_ runStateGenT runStateGenT_ runStateGenSTrunStateGenST_ uniformListM uniformListRMmkStdGen mkStdGen64uniformViaFiniteM isInRangeOrd isInRangeEnum uniformWordRuniformDouble01MuniformDoublePositive01M scaleFloatinguniformFloat01MuniformFloatPositive01M uniformEnumM uniformEnumRMSeedGenfromSeedtoSeed fromSeed64toSeed64seedSize seedSizeProxymkSeedwithSeed withSeedMseedGenTypeNamemkSeedFromByteStringunSeedunSeedToByteString withSeedFilenonEmptyToSeednonEmptyFromSeedRandomrandomRrandomRsrandomsuniformuniformRuniforms uniformRs uniformList uniformListRuniformShuffleList genByteStringuniformByteStringuniformFillMutableByteArray initStdGen setStdGen getStdGen newStdGen getStdRandom randomRIOrandomIO$fRandom(,,,,,,)$fRandom(,,,,,)$fRandom(,,,,) $fRandom(,,,) $fRandom(,,) $fRandom(,) $fRandomFloat$fRandomDouble $fRandomBool $fRandomChar$fRandomCDouble$fRandomCFloat$fRandomCUIntMax$fRandomCIntMax$fRandomCUIntPtr$fRandomCIntPtr$fRandomCULLong$fRandomCLLong$fRandomCSigAtomic$fRandomCWchar $fRandomCSize$fRandomCPtrdiff$fRandomCULong $fRandomCLong $fRandomCUInt $fRandomCInt$fRandomCUShort$fRandomCShort$fRandomCUChar$fRandomCSChar $fRandomCChar $fRandomCBool$fRandomWord64$fRandomWord32$fRandomWord16 $fRandomWord8 $fRandomWord $fRandomInt $fRandomInt64 $fRandomInt32 $fRandomInt16 $fRandomInt8$fRandomIntegerTGenunTGenTGenMunTGenMSTGenunSTGenSTGenMunSTGenMIOGenunIOGenIOGenMunIOGenM AtomicGen unAtomicGen AtomicGenM unAtomicGenM RandomGenMapplyRandomGenMuniformShuffleListMwithMutableGenwithMutableGen_withSeedMutableGen_uniformByteStringM newAtomicGenM newIOGenM applyIOGen newSTGenM applySTGenrunSTGen runSTGen_newTGenM newTGenMIO applyTGen$fRandomGenMStateGenMrm$fStatefulGenAtomicGenMm$fRandomGenMAtomicGenMrm$fThawedGenAtomicGenm$fFrozenGenAtomicGenm$fSeedGenAtomicGen$fStatefulGenIOGenMm$fRandomGenMIOGenMrm$fThawedGenIOGenm$fFrozenGenIOGenm$fSeedGenIOGen$fStatefulGenSTGenMST$fRandomGenMSTGenMrST$fThawedGenSTGenST$fFrozenGenSTGenST$fSeedGenSTGen$fStatefulGenTGenMSTM$fRandomGenMTGenMrSTM$fThawedGenTGenSTM$fFrozenGenTGenSTM $fSeedGenTGen$fEqTGen $fOrdTGen $fShowTGen$fRandomGenTGen$fSplitGenTGen$fStorableTGen $fNFDataTGen $fEqSTGen $fOrdSTGen $fShowSTGen$fRandomGenSTGen$fSplitGenSTGen$fStorableSTGen $fNFDataSTGen $fEqIOGen $fOrdIOGen $fShowIOGen$fRandomGenIOGen$fSplitGenIOGen$fStorableIOGen $fNFDataIOGen $fEqAtomicGen$fOrdAtomicGen$fShowAtomicGen$fRandomGenAtomicGen$fSplitGenAtomicGen$fStorableAtomicGen$fNFDataAtomicGenshortByteStringToByteStringfillMutableArrayFromListgenSwapIndices shuffleListMbaseGHC.STST shuffleListSTtransformers-0.6.1.0Control.Monad.Trans.Class MonadTrans indexWord8 indexWord64LEindexByteSliceWord64LE writeWord64LEioToSTwordSizeInBitsnewMutableByteArraynewPinnedMutableByteArrayfreezeMutableByteArray writeWord8writeByteSliceWord64LEsizeOfByteArrayshortByteStringToByteArraybyteArrayToShortByteStringgetSizeOfMutableByteArrayArray MutableArraynewMutableArrayfreezeMutableArray writeArray GHC.GenericsGeneric CardinalityShift$fRealCardinalityGHC.RealIntegral$fEnumCardinalityCard cardinalitytoFinite fromFiniteGFinite gcardinality toGFinite fromGFiniteGUniformControl.Monad.Trans.ContContTGHC.Basefmap>>=Rep guniformMGHC.WordWord32Word64Word8Word16Data.Array.Byte ByteArraybytestring-0.11.5.2Data.ByteString.Short.InternalShortByteStringGHC.Errerrorghc-prim GHC.TypesInt ghc-bignumGHC.Num.IntegerIntegerFalseMutableByteArray Control.Monad.Trans.State.StrictStateStateT theStdGenWord GHC.ClassesOrdGHC.EnumEnumDoubleFloatuniformIntegralMboundedExclusiveIntegralM#boundedByPowerOf2ExclusiveIntegralMintegralWordSizeuniformIntegralWordsunbiasedWordMult32RMunbiasedWordMult32unbiasedWordMult32ExclusiveunsignedBitmaskWithRejectionRMsignedBitmaskWithRejectionRMunsignedBitmaskWithRejectionM$fUniformRangeFloat$fUniformRangeDouble$fUniformRangeCDouble$fUniformRangeCFloatunStdGen"defaultUnsafeFillMutableByteArrayTControl.Monad.FailfailBoundedCharData.ByteString.Internal.Type ByteString buildRandoms GHC.Conc.SyncTVar GHC.STRefSTRef GHC.IORefIORefSTMIO