úÎ~'xÊ)      !"#$%&'((c) 2009-2012 Bryan O'SullivanBSD3bos@serpentine.com experimentalportableNone +3;=HKM(An immutable snapshot of the state of a .Convert seed into vector.%A shorter name for PRNG state in the ) monad.%A shorter name for PRNG state in the * monad.,State of the pseudo-random number generator.TThe class of types for which we can generate uniformly distributed random variates.úThe uniform PRNG uses Marsaglia's MWC256 (also known as MWC8222) multiply-with-carry generator, which has a period of 2^8222 and fares well in tests of randomness. It is also extremely fast, between 2 and 3 times faster than the Mersenne Twister.Notew: Marsaglia's PRNG is not known to be cryptographically secure, so you should not use it for cryptographic operations.fGenerate a single uniformly distributed random variate. The range of values produced varies by type:CFor fixed-width integral types, the type's entire range is used.ÃFor floating point numbers, the range (0,1] is used. Zero is explicitly excluded, to allow variates to be used in statistical calculations that require non-zero values (e.g. uses of the + function).To generate a ,I variate with a range of [0,1), subtract 2**(-33). To do the same with - variates, subtract 2**(-53).HGenerate single uniformly distributed random variable in a given range.+For integral types inclusive range is used.QFor floating point numbers range (a,b] is used if one ignores rounding errors..Constrain the type of an action to run in the * monad. .Constrain the type of an action to run in the ) monad. 3Create a generator for variates using a fixed seed. ÝCreate a generator for variates using the given seed, of which up to 256 elements will be used. For arrays of less than 256 elements, part of the default seed will be used to finish initializing the generator's state. Examples: initialize (singleton 42) ,initialize (fromList [4, 8, 15, 16, 23, 42])^If a seed contains fewer than 256 elements, it is first used verbatim, then its elements are .Hed against elements of the default seed until 256 elements are reached.¶If a seed contains exactly 258 elements, then the last two elements are used to set the generator's initial state. This allows for complete generator reproducibility, so that e.g.  gen' == gen in the following example: gen' <-   .  =<<  Convert vector to . It acts similarily to   and will accept any vector. If you want to pass seed immediately to restore you better call initialize directly since following law holds: !restore (toSeed v) = initialize v Save the state of a , for later use by . Create a new # that mirrors the state of a saved ./Acquire seed from devurandomPSeed a PRNG with data from the system's fast source of pseudo-random numbers (" /dev/urandom4" on Unix-like systems), then run the given action.ƒThis is a somewhat expensive function, and is intended to be called only occasionally (e.g. once per thread). You should use the - it creates to generate many random numbers.NoteÑ: on Windows, this code does not yet use the native Cryptographic API as a source of random numbers (it uses the system clock instead). As a result, the sequences it generates may not be highly independent.bSeed a PRNG with data from the system's fast source of pseudo-random numbers. All the caveats of  apply here as well.0QCompute the next index into the state pool. This is simply addition modulo 256.\Generate a vector of pseudo-random variates. This is not necessarily faster than invoking P repeatedly in a loop, but it may be more convenient to use in some situations.@1234567 89 :/0;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\    ;1234567 89 :/0;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\(c) 2012 Bryan O'SullivanBSD3bos@serpentine.com experimentalportableNone!"3MWGenerate a normally distributed random variate with given mean and standard deviation.QGenerate a normally distributed random variate with zero mean and unit variance.ÓThe implementation uses Doornik's modified ziggurat algorithm. Compared to the ziggurat algorithm usually used, this is slower, but generates more independent variates that pass stringent tests of randomness.5Generate an exponentially distributed random variate.<Generate truncated exponentially distributed random variate.0Random variate generator for gamma distribution.9Random variate generator for the chi square distribution.ŒRandom variate generator for the geometric distribution, computing the number of failures before success. Distribution's support is [0..].vRandom variate generator for geometric distribution for number of trials. Distribution's support is [1..] (i.e. just  shifted by 1)..Random variate generator for Beta distribution3Random variate generator for Dirichlet distribution3Random variate generator for Bernoulli distribution6Random variate generator for categorical distribution.ANote that if you need to generate a lot of variates functions  System.Random.MWC.CondensedTable will offer better performance. If only few is needed this function will faster since it avoids costs of setting up table.lRandom variate generator for uniformly distributed permutations. It returns random permutation of vector  [0 .. n-1]. This is the Fisher-Yates shuffleLRandom variate generator for a uniformly distributed shuffle of a vector.]^MeanStandard deviation_`aScale parameter GeneratorScale parameterDRange to which distribution is truncated. Values may be negative. Generator.Shape parameterScale parameter GeneratorNumber of degrees of freedom Generatorp" success probability lies in (0,1] Generatorp" success probability lies in (0,1] Generator alpha (>0) beta (>0) Generatorcontainer of parameters Generator'Probability of success (returning True) GeneratorList of weights [>0] Generatorbc]^_`abc(c) 2012 Aleksey KhudyakovBSD3bos@serpentine.com experimentalportableNone3 A "C that uses boxed vectors, and is able to hold any type of element.!A " that uses unboxed vectors."eA lookup table for arbitrary discrete distributions. It allows the generation of random variates in O(1)2. Note that probability is quantized in units of 1/2^32R, and all distributions with infinite support (e.g. Poisson) should be truncated.#0Generate a random value using a condensed table.$ÿ8Generate a condensed lookup table from a list of outcomes with given probabilities. The vector should be non-empty and the probabilites should be non-negative and sum to 1. If this is not the case, this algorithm will construct a table for some distribution that may bear no resemblance to what you intended.%Same as $} but treats number as weights not probilities. Non-positive weights are discarded, and those remaining are normalized to 1.&OGenerate a condensed lookup table from integer weights. Weights should sum to 2^32‡. If they don't, the algorithm will alter the weights so that they do. This approach should work reasonably well for rounding errors.'ÄCreate a lookup table for the Poisson distibution. Note that table construction may have significant cost. For » < 100 it takes as much time to build table as generation of 1000-30000 variates.(4Create a lookup table for the binomial distribution. !"d#e$%&fg'(Number of triesProbability of successh !"#$%&'( " !#$%&'( !"d#e$%&fg'(hi      !"#$%&'()*+,-./012-34015016-789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdeefghij&klmjnmwc-random-0.13.2.2System.Random.MWCSystem.Random.MWC.Distributions System.Random.MWC.CondensedTableSeedfromSeedGenSTGenIOGenVariateuniformuniformRasGenIOasGenSTcreate initializetoSeedsaverestorewithSystemRandomcreateSystemRandom uniformVectornormalstandard exponential truncatedExpgamma chiSquare geometric0 geometric1beta dirichlet bernoulli categoricaluniformPermutationuniformShuffleCondensedTableVCondensedTableUCondensedTable genFromTabletableFromProbabilitiestableFromWeightstableFromIntWeights tablePoisson tableBinomialbaseGHC.STSTghc-prim GHC.TypesIO GHC.FloatlogFloatDouble Data.BitsxoracquireSeedSystem nextIndexUnsigned wordsTo64Bit wordToBool wordToFloat wordsToDoubleioffcoffacquireSeedTimeaa uniformWord32uniform1uniform2subadd uniformRange defaultSeedTFCo:R:UnsignedWordTFCo:R:UnsignedIntTFCo:R:UnsignedWord64TFCo:R:UnsignedWord32TFCo:R:UnsignedWord16TFCo:R:UnsignedWord8TFCo:R:UnsignedInt64TFCo:R:UnsignedInt32TFCo:R:UnsignedInt16TFCo:R:UnsignedInt8$fVariate(,,,) $fVariate(,,) $fVariate(,) $fVariateWord $fVariateInt$fVariateDouble$fVariateFloat $fVariateBool$fVariateWord64$fVariateWord32$fVariateWord16$fVariateWord8$fVariateInt64$fVariateInt32$fVariateInt16 $fVariateInt8TblocksrNormratiossqrpkgError lookupTabledigitcorrectWeights