<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>System.Random.MWC</title><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean" /><script src="haddock-util.js" type="text/javascript"></script><script type="text/javascript">//<![CDATA[ window.onload = function () {pageLoad();setSynopsis("mini_System-Random-MWC.html");}; //]]> </script></head><body><div id="package-header"><ul class="links" id="page-menu"><li><a href="src/System-Random-MWC.html">Source</a></li><li><a href="index.html">Contents</a></li><li><a href="doc-index.html">Index</a></li></ul><p class="caption">mwc-random-0.12.0.1: Fast, high quality pseudo random number generation</p></div><div id="content"><div id="module-header"><table class="info"><tr><th>Portability</th><td>portable</td></tr><tr><th>Stability</th><td>experimental</td></tr><tr><th>Maintainer</th><td>bos@serpentine.com</td></tr><tr><th>Safe Haskell</th><td>Safe-Infered</td></tr></table><p class="caption">System.Random.MWC</p></div><div id="table-of-contents"><p class="caption">Contents</p><ul><li><a href="#g:1">Gen: Pseudo-Random Number Generators </a><ul><li><a href="#g:2">Type helpers </a></li></ul></li><li><a href="#g:3">Variates: uniformly distributed values </a></li><li><a href="#g:4">Seed: state management </a></li><li><a href="#g:5">References </a></li></ul></div><div id="description"><p class="caption">Description</p><div class="doc"><p>Pseudo-random number generation. This module contains code for generating high quality random numbers that follow a uniform distribution. </p><p>For non-uniform distributions, see the <code><a href="System-Random-MWC.html#t:Distributions">Distributions</a></code> module. </p><p>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. </p><p>The generator state is stored in the <code><a href="System-Random-MWC.html#t:Gen">Gen</a></code> data type. It can be created in several ways: </p><ol><li> Using the <code><a href="System-Random-MWC.html#v:withSystemRandom">withSystemRandom</a></code> call, which creates a random state. </li><li> Supply your own seed to <code><a href="System-Random-MWC.html#v:initialize">initialize</a></code> function. </li><li> Finally, <code><a href="System-Random-MWC.html#v:create">create</a></code> makes a generator from a fixed seed. Generators created in this way aren't really random. </li></ol><p>For repeatability, the state of the generator can be snapshotted and replayed using the <code><a href="System-Random-MWC.html#v:save">save</a></code> and <code><a href="System-Random-MWC.html#v:restore">restore</a></code> functions. </p><p>The simplest use is to generate a vector of uniformly distributed values: </p><pre> vs <a href="- withSystemRandom . asGenST $ \gen -">- withSystemRandom . asGenST $ \gen -</a> uniformVector gen 100 </pre><p>These values can be of any type which is an instance of the class <code><a href="System-Random-MWC.html#t:Variate">Variate</a></code>. </p><p>To generate random values on demand, first <code><a href="System-Random-MWC.html#v:create">create</a></code> a random number generator. </p><pre> gen <- create </pre><p>Hold onto this generator and use it wherever random values are required (creating a new generator is expensive compared to generating a random number, so you don't want to throw them away). Get a random value using <code><a href="System-Random-MWC.html#v:uniform">uniform</a></code> or <code><a href="System-Random-MWC.html#v:uniformR">uniformR</a></code>: </p><pre> v <- uniform gen </pre><pre> v <- uniformR (1, 52) gen </pre></div></div><div id="synopsis"><p id="control.syn" class="caption expander" onclick="toggleSection('syn')">Synopsis</p><ul id="section.syn" class="hide" onclick="toggleSection('syn')"><li class="src short"><span class="keyword">data</span> <a href="#t:Gen">Gen</a> s</li><li class="src short"><a href="#v:create">create</a> :: <a href="/usr/share/doc/ghc/html/libraries/primitive-0.4.1/Control-Monad-Primitive.html#t:PrimMonad">PrimMonad</a> m => m (<a href="System-Random-MWC.html#t:Gen">Gen</a> (<a href="/usr/share/doc/ghc/html/libraries/primitive-0.4.1/Control-Monad-Primitive.html#t:PrimState">PrimState</a> m))</li><li class="src short"><a href="#v:initialize">initialize</a> :: (<a href="/usr/share/doc/ghc/html/libraries/primitive-0.4.1/Control-Monad-Primitive.html#t:PrimMonad">PrimMonad</a> m, <a href="/usr/share/doc/ghc/html/libraries/vector-0.9.1/Data-Vector-Generic.html#t:Vector">Vector</a> v <a href="/usr/share/doc/ghc/html/libraries/base-4.5.0.0/Data-Word.html#t:Word32">Word32</a>) => v <a href="/usr/share/doc/ghc/html/libraries/base-4.5.0.0/Data-Word.html#t:Word32">Word32</a> -> m (<a href="System-Random-MWC.html#t:Gen">Gen</a> (<a href="/usr/share/doc/ghc/html/libraries/primitive-0.4.1/Control-Monad-Primitive.html#t:PrimState">PrimState</a> m))</li><li class="src short"><a href="#v:withSystemRandom">withSystemRandom</a> :: <a href="/usr/share/doc/ghc/html/libraries/primitive-0.4.1/Control-Monad-Primitive.html#t:PrimMonad">PrimMonad</a> m => (<a href="System-Random-MWC.html#t:Gen">Gen</a> (<a href="/usr/share/doc/ghc/html/libraries/primitive-0.4.1/Control-Monad-Primitive.html#t:PrimState">PrimState</a> m) -> m a) -> <a href="/usr/share/doc/ghc/html/libraries/base-4.5.0.0/System-IO.html#t:IO">IO</a> a</li><li class="src short"><span class="keyword">type</span> <a href="#t:GenIO">GenIO</a> = <a href="System-Random-MWC.html#t:Gen">Gen</a> (<a href="/usr/share/doc/ghc/html/libraries/primitive-0.4.1/Control-Monad-Primitive.html#t:PrimState">PrimState</a> <a href="/usr/share/doc/ghc/html/libraries/base-4.5.0.0/System-IO.html#t:IO">IO</a>)</li><li class="src short"><span class="keyword">type</span> <a href="#t:GenST">GenST</a> s = <a href="System-Random-MWC.html#t:Gen">Gen</a> (<a href="/usr/share/doc/ghc/html/libraries/primitive-0.4.1/Control-Monad-Primitive.html#t:PrimState">PrimState</a> (<a href="/usr/share/doc/ghc/html/libraries/base-4.5.0.0/Control-Monad-ST-Safe.html#t:ST">ST</a> s))</li><li class="src short"><a href="#v:asGenIO">asGenIO</a> :: (<a href="System-Random-MWC.html#t:GenIO">GenIO</a> -> <a href="/usr/share/doc/ghc/html/libraries/base-4.5.0.0/System-IO.html#t:IO">IO</a> a) -> <a href="System-Random-MWC.html#t:GenIO">GenIO</a> -> <a href="/usr/share/doc/ghc/html/libraries/base-4.5.0.0/System-IO.html#t:IO">IO</a> a</li><li class="src short"><a href="#v:asGenST">asGenST</a> :: (<a href="System-Random-MWC.html#t:GenST">GenST</a> s -> <a href="/usr/share/doc/ghc/html/libraries/base-4.5.0.0/Control-Monad-ST-Safe.html#t:ST">ST</a> s a) -> <a href="System-Random-MWC.html#t:GenST">GenST</a> s -> <a href="/usr/share/doc/ghc/html/libraries/base-4.5.0.0/Control-Monad-ST-Safe.html#t:ST">ST</a> s a</li><li class="src short"><span class="keyword">class</span> <a href="#t:Variate">Variate</a> a <span class="keyword">where</span><ul class="subs"><li><a href="#v:uniform">uniform</a> :: <a href="/usr/share/doc/ghc/html/libraries/primitive-0.4.1/Control-Monad-Primitive.html#t:PrimMonad">PrimMonad</a> m => <a href="System-Random-MWC.html#t:Gen">Gen</a> (<a href="/usr/share/doc/ghc/html/libraries/primitive-0.4.1/Control-Monad-Primitive.html#t:PrimState">PrimState</a> m) -> m a</li><li><a href="#v:uniformR">uniformR</a> :: <a href="/usr/share/doc/ghc/html/libraries/primitive-0.4.1/Control-Monad-Primitive.html#t:PrimMonad">PrimMonad</a> m => (a, a) -> <a href="System-Random-MWC.html#t:Gen">Gen</a> (<a href="/usr/share/doc/ghc/html/libraries/primitive-0.4.1/Control-Monad-Primitive.html#t:PrimState">PrimState</a> m) -> m a</li></ul></li><li class="src short"><a href="#v:uniformVector">uniformVector</a> :: (<a href="/usr/share/doc/ghc/html/libraries/primitive-0.4.1/Control-Monad-Primitive.html#t:PrimMonad">PrimMonad</a> m, <a href="System-Random-MWC.html#t:Variate">Variate</a> a, <a href="/usr/share/doc/ghc/html/libraries/vector-0.9.1/Data-Vector-Generic.html#t:Vector">Vector</a> v a) => <a href="System-Random-MWC.html#t:Gen">Gen</a> (<a href="/usr/share/doc/ghc/html/libraries/primitive-0.4.1/Control-Monad-Primitive.html#t:PrimState">PrimState</a> m) -> <a href="/usr/share/doc/ghc/html/libraries/base-4.5.0.0/Data-Int.html#t:Int">Int</a> -> m (v a)</li><li class="src short"><span class="keyword">data</span> <a href="#t:Seed">Seed</a> </li><li class="src short"><a href="#v:fromSeed">fromSeed</a> :: <a href="System-Random-MWC.html#t:Seed">Seed</a> -> <a href="/usr/share/doc/ghc/html/libraries/vector-0.9.1/Data-Vector-Unboxed.html#t:Vector">Vector</a> <a href="/usr/share/doc/ghc/html/libraries/base-4.5.0.0/Data-Word.html#t:Word32">Word32</a></li><li class="src short"><a href="#v:toSeed">toSeed</a> :: <a href="/usr/share/doc/ghc/html/libraries/vector-0.9.1/Data-Vector-Generic.html#t:Vector">Vector</a> v <a href="/usr/share/doc/ghc/html/libraries/base-4.5.0.0/Data-Word.html#t:Word32">Word32</a> => v <a href="/usr/share/doc/ghc/html/libraries/base-4.5.0.0/Data-Word.html#t:Word32">Word32</a> -> <a href="System-Random-MWC.html#t:Seed">Seed</a></li><li class="src short"><a href="#v:save">save</a> :: <a href="/usr/share/doc/ghc/html/libraries/primitive-0.4.1/Control-Monad-Primitive.html#t:PrimMonad">PrimMonad</a> m => <a href="System-Random-MWC.html#t:Gen">Gen</a> (<a href="/usr/share/doc/ghc/html/libraries/primitive-0.4.1/Control-Monad-Primitive.html#t:PrimState">PrimState</a> m) -> m <a href="System-Random-MWC.html#t:Seed">Seed</a></li><li class="src short"><a href="#v:restore">restore</a> :: <a href="/usr/share/doc/ghc/html/libraries/primitive-0.4.1/Control-Monad-Primitive.html#t:PrimMonad">PrimMonad</a> m => <a href="System-Random-MWC.html#t:Seed">Seed</a> -> m (<a href="System-Random-MWC.html#t:Gen">Gen</a> (<a href="/usr/share/doc/ghc/html/libraries/primitive-0.4.1/Control-Monad-Primitive.html#t:PrimState">PrimState</a> m))</li></ul></div><div id="interface"><h1 id="g:1">Gen: Pseudo-Random Number Generators </h1><div class="top"><p class="src"><span class="keyword">data</span> <a name="t:Gen" class="def">Gen</a> s <a href="src/System-Random-MWC.html#Gen" class="link">Source</a></p><div class="doc"><p>State of the pseudo-random number generator. </p></div></div><div class="top"><p class="src"><a name="v:create" class="def">create</a> :: <a href="/usr/share/doc/ghc/html/libraries/primitive-0.4.1/Control-Monad-Primitive.html#t:PrimMonad">PrimMonad</a> m => m (<a href="System-Random-MWC.html#t:Gen">Gen</a> (<a href="/usr/share/doc/ghc/html/libraries/primitive-0.4.1/Control-Monad-Primitive.html#t:PrimState">PrimState</a> m))<a href="src/System-Random-MWC.html#create" class="link">Source</a></p><div class="doc"><p>Create a generator for variates using a fixed seed. </p></div></div><div class="top"><p class="src"><a name="v:initialize" class="def">initialize</a> :: (<a href="/usr/share/doc/ghc/html/libraries/primitive-0.4.1/Control-Monad-Primitive.html#t:PrimMonad">PrimMonad</a> m, <a href="/usr/share/doc/ghc/html/libraries/vector-0.9.1/Data-Vector-Generic.html#t:Vector">Vector</a> v <a href="/usr/share/doc/ghc/html/libraries/base-4.5.0.0/Data-Word.html#t:Word32">Word32</a>) => v <a href="/usr/share/doc/ghc/html/libraries/base-4.5.0.0/Data-Word.html#t:Word32">Word32</a> -> m (<a href="System-Random-MWC.html#t:Gen">Gen</a> (<a href="/usr/share/doc/ghc/html/libraries/primitive-0.4.1/Control-Monad-Primitive.html#t:PrimState">PrimState</a> m))<a href="src/System-Random-MWC.html#initialize" class="link">Source</a></p><div class="doc"><p>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. </p><p>Examples: </p><pre> initialize (singleton 42) </pre><pre> initialize (toList [4, 8, 15, 16, 23, 42]) </pre><p>If a seed contains fewer than 256 elements, it is first used verbatim, then its elements are <code><a href="/usr/share/doc/ghc/html/libraries/base-4.5.0.0/Data-Bits.html#v:xor">xor</a></code>ed against elements of the default seed until 256 elements are reached. </p><p>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. <code>gen' == gen</code> in the following example: </p><pre>gen' <- <code><a href="System-Random-MWC.html#v:initialize">initialize</a></code> . <code><a href="System-Random-MWC.html#v:fromSeed">fromSeed</a></code> =<< <code><a href="System-Random-MWC.html#v:save">save</a></code></pre></div></div><div class="top"><p class="src"><a name="v:withSystemRandom" class="def">withSystemRandom</a> :: <a href="/usr/share/doc/ghc/html/libraries/primitive-0.4.1/Control-Monad-Primitive.html#t:PrimMonad">PrimMonad</a> m => (<a href="System-Random-MWC.html#t:Gen">Gen</a> (<a href="/usr/share/doc/ghc/html/libraries/primitive-0.4.1/Control-Monad-Primitive.html#t:PrimState">PrimState</a> m) -> m a) -> <a href="/usr/share/doc/ghc/html/libraries/base-4.5.0.0/System-IO.html#t:IO">IO</a> a<a href="src/System-Random-MWC.html#withSystemRandom" class="link">Source</a></p><div class="doc"><p>Seed a PRNG with data from the system's fast source of pseudo-random numbers ("<code>/dev/urandom</code>" on Unix-like systems), then run the given action. </p><p>This is a somewhat expensive function, and is intended to be called only occasionally (e.g. once per thread). You should use the <code><a href="System-Random-MWC.html#t:Gen">Gen</a></code> it creates to generate many random numbers. </p><p><em>Note</em>: 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. </p></div></div><h2 id="g:2">Type helpers </h2><div class="doc"><p>The functions in this package are deliberately written for flexibility, and will run in both the <code><a href="/usr/share/doc/ghc/html/libraries/base-4.5.0.0/System-IO.html#t:IO">IO</a></code> and <code><a href="/usr/share/doc/ghc/html/libraries/base-4.5.0.0/Control-Monad-ST-Safe.html#t:ST">ST</a></code> monads. </p><p>This can defeat the compiler's ability to infer a principal type in simple (and common) cases. For instance, we would like the following to work cleanly: </p><pre> import System.Random.MWC import Data.Vector.Unboxed main = do v <- withSystemRandom $ \gen -> uniformVector gen 20 print (v :: Vector Int) </pre><p>Unfortunately, the compiler cannot tell what monad <code><a href="System-Random-MWC.html#v:uniformVector">uniformVector</a></code> should execute in. The "fix" of adding explicit type annotations is not pretty: </p><pre> {-# LANGUAGE ScopedTypeVariables #-} import Control.Monad.ST main = do vs <- withSystemRandom $ \(gen::GenST s) -> uniformVector gen 20 :: ST s (Vector Int) print vs </pre><p>As a more readable alternative, this library provides <code><a href="System-Random-MWC.html#v:asGenST">asGenST</a></code> and <code><a href="System-Random-MWC.html#v:asGenIO">asGenIO</a></code> to constrain the types appropriately. We can get rid of the explicit type annotations as follows: </p><pre> main = do vs <- withSystemRandom . asGenST $ \gen -> uniformVector gen 20 print (vs :: Vector Int) </pre><p>This is almost as compact as the original code that the compiler rejected. </p></div><div class="top"><p class="src"><span class="keyword">type</span> <a name="t:GenIO" class="def">GenIO</a> = <a href="System-Random-MWC.html#t:Gen">Gen</a> (<a href="/usr/share/doc/ghc/html/libraries/primitive-0.4.1/Control-Monad-Primitive.html#t:PrimState">PrimState</a> <a href="/usr/share/doc/ghc/html/libraries/base-4.5.0.0/System-IO.html#t:IO">IO</a>)<a href="src/System-Random-MWC.html#GenIO" class="link">Source</a></p><div class="doc"><p>A shorter name for PRNG state in the <code><a href="/usr/share/doc/ghc/html/libraries/base-4.5.0.0/System-IO.html#t:IO">IO</a></code> monad. </p></div></div><div class="top"><p class="src"><span class="keyword">type</span> <a name="t:GenST" class="def">GenST</a> s = <a href="System-Random-MWC.html#t:Gen">Gen</a> (<a href="/usr/share/doc/ghc/html/libraries/primitive-0.4.1/Control-Monad-Primitive.html#t:PrimState">PrimState</a> (<a href="/usr/share/doc/ghc/html/libraries/base-4.5.0.0/Control-Monad-ST-Safe.html#t:ST">ST</a> s))<a href="src/System-Random-MWC.html#GenST" class="link">Source</a></p><div class="doc"><p>A shorter name for PRNG state in the <code><a href="/usr/share/doc/ghc/html/libraries/base-4.5.0.0/Control-Monad-ST-Safe.html#t:ST">ST</a></code> monad. </p></div></div><div class="top"><p class="src"><a name="v:asGenIO" class="def">asGenIO</a> :: (<a href="System-Random-MWC.html#t:GenIO">GenIO</a> -> <a href="/usr/share/doc/ghc/html/libraries/base-4.5.0.0/System-IO.html#t:IO">IO</a> a) -> <a href="System-Random-MWC.html#t:GenIO">GenIO</a> -> <a href="/usr/share/doc/ghc/html/libraries/base-4.5.0.0/System-IO.html#t:IO">IO</a> a<a href="src/System-Random-MWC.html#asGenIO" class="link">Source</a></p><div class="doc"><p>Constrain the type of an action to run in the <code><a href="/usr/share/doc/ghc/html/libraries/base-4.5.0.0/System-IO.html#t:IO">IO</a></code> monad. </p></div></div><div class="top"><p class="src"><a name="v:asGenST" class="def">asGenST</a> :: (<a href="System-Random-MWC.html#t:GenST">GenST</a> s -> <a href="/usr/share/doc/ghc/html/libraries/base-4.5.0.0/Control-Monad-ST-Safe.html#t:ST">ST</a> s a) -> <a href="System-Random-MWC.html#t:GenST">GenST</a> s -> <a href="/usr/share/doc/ghc/html/libraries/base-4.5.0.0/Control-Monad-ST-Safe.html#t:ST">ST</a> s a<a href="src/System-Random-MWC.html#asGenST" class="link">Source</a></p><div class="doc"><p>Constrain the type of an action to run in the <code><a href="/usr/share/doc/ghc/html/libraries/base-4.5.0.0/Control-Monad-ST-Safe.html#t:ST">ST</a></code> monad. </p></div></div><h1 id="g:3">Variates: uniformly distributed values </h1><div class="top"><p class="src"><span class="keyword">class</span> <a name="t:Variate" class="def">Variate</a> a <span class="keyword">where</span><a href="src/System-Random-MWC.html#Variate" class="link">Source</a></p><div class="doc"><p>The class of types for which we can generate uniformly distributed random variates. </p><p>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. </p><p><em>Note</em>: Marsaglia's PRNG is not known to be cryptographically secure, so you should not use it for cryptographic operations. </p></div><div class="subs methods"><p class="caption">Methods</p><p class="src"><a name="v:uniform" class="def">uniform</a> :: <a href="/usr/share/doc/ghc/html/libraries/primitive-0.4.1/Control-Monad-Primitive.html#t:PrimMonad">PrimMonad</a> m => <a href="System-Random-MWC.html#t:Gen">Gen</a> (<a href="/usr/share/doc/ghc/html/libraries/primitive-0.4.1/Control-Monad-Primitive.html#t:PrimState">PrimState</a> m) -> m a<a href="src/System-Random-MWC.html#uniform" class="link">Source</a></p><div class="doc"><p>Generate a single uniformly distributed random variate. The range of values produced varies by type: </p><ul><li> For fixed-width integral types, the type's entire range is used. </li><li> 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 <code><a href="/usr/share/doc/ghc/html/libraries/base-4.5.0.0/Prelude.html#v:log">log</a></code> function). </li></ul><p>To generate a <code><a href="/usr/share/doc/ghc/html/libraries/base-4.5.0.0/Prelude.html#t:Float">Float</a></code> variate with a range of [0,1), subtract 2**(-33). To do the same with <code><a href="/usr/share/doc/ghc/html/libraries/base-4.5.0.0/Prelude.html#t:Double">Double</a></code> variates, subtract 2**(-53). </p></div><p class="src"><a name="v:uniformR" class="def">uniformR</a> :: <a href="/usr/share/doc/ghc/html/libraries/primitive-0.4.1/Control-Monad-Primitive.html#t:PrimMonad">PrimMonad</a> m => (a, a) -> <a href="System-Random-MWC.html#t:Gen">Gen</a> (<a href="/usr/share/doc/ghc/html/libraries/primitive-0.4.1/Control-Monad-Primitive.html#t:PrimState">PrimState</a> m) -> m a<a href="src/System-Random-MWC.html#uniformR" class="link">Source</a></p><div class="doc"><p>Generate single uniformly distributed random variable in a given range. </p><ul><li> For integral types inclusive range is used. </li><li> For floating point numbers range (a,b] is used if one ignores rounding errors. </li></ul></div></div><div class="subs instances"><p id="control.i:Variate" class="caption collapser" onclick="toggleSection('i:Variate')">Instances</p><div id="section.i:Variate" class="show"><table><tr><td class="src"><a href="System-Random-MWC.html#t:Variate">Variate</a> <a href="/usr/share/doc/ghc/html/libraries/base-4.5.0.0/Data-Bool.html#t:Bool">Bool</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="System-Random-MWC.html#t:Variate">Variate</a> <a href="/usr/share/doc/ghc/html/libraries/base-4.5.0.0/Prelude.html#t:Double">Double</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="System-Random-MWC.html#t:Variate">Variate</a> <a href="/usr/share/doc/ghc/html/libraries/base-4.5.0.0/Prelude.html#t:Float">Float</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="System-Random-MWC.html#t:Variate">Variate</a> <a href="/usr/share/doc/ghc/html/libraries/base-4.5.0.0/Data-Int.html#t:Int">Int</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="System-Random-MWC.html#t:Variate">Variate</a> <a href="/usr/share/doc/ghc/html/libraries/base-4.5.0.0/Data-Int.html#t:Int8">Int8</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="System-Random-MWC.html#t:Variate">Variate</a> <a href="/usr/share/doc/ghc/html/libraries/base-4.5.0.0/Data-Int.html#t:Int16">Int16</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="System-Random-MWC.html#t:Variate">Variate</a> <a href="/usr/share/doc/ghc/html/libraries/base-4.5.0.0/Data-Int.html#t:Int32">Int32</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="System-Random-MWC.html#t:Variate">Variate</a> <a href="/usr/share/doc/ghc/html/libraries/base-4.5.0.0/Data-Int.html#t:Int64">Int64</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="System-Random-MWC.html#t:Variate">Variate</a> <a href="/usr/share/doc/ghc/html/libraries/base-4.5.0.0/Data-Word.html#t:Word">Word</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="System-Random-MWC.html#t:Variate">Variate</a> <a href="/usr/share/doc/ghc/html/libraries/base-4.5.0.0/Data-Word.html#t:Word8">Word8</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="System-Random-MWC.html#t:Variate">Variate</a> <a href="/usr/share/doc/ghc/html/libraries/base-4.5.0.0/Data-Word.html#t:Word16">Word16</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="System-Random-MWC.html#t:Variate">Variate</a> <a href="/usr/share/doc/ghc/html/libraries/base-4.5.0.0/Data-Word.html#t:Word32">Word32</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="System-Random-MWC.html#t:Variate">Variate</a> <a href="/usr/share/doc/ghc/html/libraries/base-4.5.0.0/Data-Word.html#t:Word64">Word64</a></td><td class="doc empty"> </td></tr><tr><td class="src">(<a href="System-Random-MWC.html#t:Variate">Variate</a> a, <a href="System-Random-MWC.html#t:Variate">Variate</a> b) => <a href="System-Random-MWC.html#t:Variate">Variate</a> (a, b)</td><td class="doc empty"> </td></tr><tr><td class="src">(<a href="System-Random-MWC.html#t:Variate">Variate</a> a, <a href="System-Random-MWC.html#t:Variate">Variate</a> b, <a href="System-Random-MWC.html#t:Variate">Variate</a> c) => <a href="System-Random-MWC.html#t:Variate">Variate</a> (a, b, c)</td><td class="doc empty"> </td></tr><tr><td class="src">(<a href="System-Random-MWC.html#t:Variate">Variate</a> a, <a href="System-Random-MWC.html#t:Variate">Variate</a> b, <a href="System-Random-MWC.html#t:Variate">Variate</a> c, <a href="System-Random-MWC.html#t:Variate">Variate</a> d) => <a href="System-Random-MWC.html#t:Variate">Variate</a> (a, b, c, d)</td><td class="doc empty"> </td></tr></table></div></div></div><div class="top"><p class="src"><a name="v:uniformVector" class="def">uniformVector</a> :: (<a href="/usr/share/doc/ghc/html/libraries/primitive-0.4.1/Control-Monad-Primitive.html#t:PrimMonad">PrimMonad</a> m, <a href="System-Random-MWC.html#t:Variate">Variate</a> a, <a href="/usr/share/doc/ghc/html/libraries/vector-0.9.1/Data-Vector-Generic.html#t:Vector">Vector</a> v a) => <a href="System-Random-MWC.html#t:Gen">Gen</a> (<a href="/usr/share/doc/ghc/html/libraries/primitive-0.4.1/Control-Monad-Primitive.html#t:PrimState">PrimState</a> m) -> <a href="/usr/share/doc/ghc/html/libraries/base-4.5.0.0/Data-Int.html#t:Int">Int</a> -> m (v a)<a href="src/System-Random-MWC.html#uniformVector" class="link">Source</a></p><div class="doc"><p>Generate a vector of pseudo-random variates. This is not necessarily faster than invoking <code><a href="System-Random-MWC.html#v:uniform">uniform</a></code> repeatedly in a loop, but it may be more convenient to use in some situations. </p></div></div><h1 id="g:4">Seed: state management </h1><div class="top"><p class="src"><span class="keyword">data</span> <a name="t:Seed" class="def">Seed</a> <a href="src/System-Random-MWC.html#Seed" class="link">Source</a></p><div class="doc"><p>An immutable snapshot of the state of a <code><a href="System-Random-MWC.html#t:Gen">Gen</a></code>. </p></div><div class="subs instances"><p id="control.i:Seed" class="caption collapser" onclick="toggleSection('i:Seed')">Instances</p><div id="section.i:Seed" class="show"><table><tr><td class="src"><a href="/usr/share/doc/ghc/html/libraries/base-4.5.0.0/Data-Eq.html#t:Eq">Eq</a> <a href="System-Random-MWC.html#t:Seed">Seed</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="/usr/share/doc/ghc/html/libraries/base-4.5.0.0/Text-Show.html#t:Show">Show</a> <a href="System-Random-MWC.html#t:Seed">Seed</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="/usr/share/doc/ghc/html/libraries/base-4.5.0.0/Data-Typeable-Internal.html#t:Typeable">Typeable</a> <a href="System-Random-MWC.html#t:Seed">Seed</a></td><td class="doc empty"> </td></tr></table></div></div></div><div class="top"><p class="src"><a name="v:fromSeed" class="def">fromSeed</a> :: <a href="System-Random-MWC.html#t:Seed">Seed</a> -> <a href="/usr/share/doc/ghc/html/libraries/vector-0.9.1/Data-Vector-Unboxed.html#t:Vector">Vector</a> <a href="/usr/share/doc/ghc/html/libraries/base-4.5.0.0/Data-Word.html#t:Word32">Word32</a><a href="src/System-Random-MWC.html#fromSeed" class="link">Source</a></p><div class="doc"><p>Convert seed into vector. </p></div></div><div class="top"><p class="src"><a name="v:toSeed" class="def">toSeed</a> :: <a href="/usr/share/doc/ghc/html/libraries/vector-0.9.1/Data-Vector-Generic.html#t:Vector">Vector</a> v <a href="/usr/share/doc/ghc/html/libraries/base-4.5.0.0/Data-Word.html#t:Word32">Word32</a> => v <a href="/usr/share/doc/ghc/html/libraries/base-4.5.0.0/Data-Word.html#t:Word32">Word32</a> -> <a href="System-Random-MWC.html#t:Seed">Seed</a><a href="src/System-Random-MWC.html#toSeed" class="link">Source</a></p><div class="doc"><p>Convert vector to <code><a href="System-Random-MWC.html#t:Seed">Seed</a></code>. It acts similarily to <code><a href="System-Random-MWC.html#v:initialize">initialize</a></code> and will accept any vector. If you want to pass seed immediately to restore you better call initialize directly since following law holds: </p><pre> restore (toSeed v) = initialize v </pre></div></div><div class="top"><p class="src"><a name="v:save" class="def">save</a> :: <a href="/usr/share/doc/ghc/html/libraries/primitive-0.4.1/Control-Monad-Primitive.html#t:PrimMonad">PrimMonad</a> m => <a href="System-Random-MWC.html#t:Gen">Gen</a> (<a href="/usr/share/doc/ghc/html/libraries/primitive-0.4.1/Control-Monad-Primitive.html#t:PrimState">PrimState</a> m) -> m <a href="System-Random-MWC.html#t:Seed">Seed</a><a href="src/System-Random-MWC.html#save" class="link">Source</a></p><div class="doc"><p>Save the state of a <code><a href="System-Random-MWC.html#t:Gen">Gen</a></code>, for later use by <code><a href="System-Random-MWC.html#v:restore">restore</a></code>. </p></div></div><div class="top"><p class="src"><a name="v:restore" class="def">restore</a> :: <a href="/usr/share/doc/ghc/html/libraries/primitive-0.4.1/Control-Monad-Primitive.html#t:PrimMonad">PrimMonad</a> m => <a href="System-Random-MWC.html#t:Seed">Seed</a> -> m (<a href="System-Random-MWC.html#t:Gen">Gen</a> (<a href="/usr/share/doc/ghc/html/libraries/primitive-0.4.1/Control-Monad-Primitive.html#t:PrimState">PrimState</a> m))<a href="src/System-Random-MWC.html#restore" class="link">Source</a></p><div class="doc"><p>Create a new <code><a href="System-Random-MWC.html#t:Gen">Gen</a></code> that mirrors the state of a saved <code><a href="System-Random-MWC.html#t:Seed">Seed</a></code>. </p></div></div><h1 id="g:5">References </h1><div class="doc"><ul><li> Marsaglia, G. (2003) Seeds for random number generators. <em>Communications of the ACM</em> 46(5):90–93. <a href="http://doi.acm.org/10.1145/769800.769827">http://doi.acm.org/10.1145/769800.769827</a> </li><li> Thomas, D.B.; Leong, P.G.W.; Luk, W.; Villasenor, J.D. (2007). Gaussian random number generators. <em>ACM Computing Surveys</em> 39(4). <a href="http://www.cse.cuhk.edu.hk/~phwl/mt/public/archives/papers/grng_acmcs07.pdf">http://www.cse.cuhk.edu.hk/~phwl/mt/public/archives/papers/grng_acmcs07.pdf</a> </li></ul></div></div></div><div id="footer"><p>Produced by <a href="http://www.haskell.org/haddock/">Haddock</a> version 2.10.0</p></div></body></html>