Sophie

Sophie

distrib > Mageia > 5 > i586 > media > core-release > by-pkgid > 6e204a966e8c42d976f99a1700ce5f20 > files > 3847

ghc-7.4.2-4.mga5.i586.rpm

<!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>Random</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_Random.html");};
//]]>
</script></head><body><div id="package-header"><ul class="links" id="page-menu"><li><a href="index.html">Contents</a></li><li><a href="doc-index.html">Index</a></li></ul><p class="caption">haskell98-2.0.0.1: Compatibility with Haskell 98</p></div><div id="content"><div id="module-header"><table class="info"><tr><th>Safe Haskell</th><td>Trustworthy</td></tr></table><p class="caption">Random</p></div><div id="table-of-contents"><p class="caption">Contents</p><ul><li><a href="#g:1">Random number generators
</a><ul><li><a href="#g:2">Standard random number generators
</a></li><li><a href="#g:3">The global random number generator
</a></li></ul></li><li><a href="#g:4">Random values of various types
</a></li><li><a href="#g:5">References
</a></li></ul></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">class</span>  <a href="#t:RandomGen">RandomGen</a> g  <span class="keyword">where</span><ul class="subs"><li><a href="#v:next">next</a> :: g -&gt; (<a href="Prelude.html#t:Int">Int</a>, g)</li><li><a href="#v:split">split</a> :: g -&gt; (g, g)</li><li><a href="#v:genRange">genRange</a> :: g -&gt; (<a href="Prelude.html#t:Int">Int</a>, <a href="Prelude.html#t:Int">Int</a>)</li></ul></li><li class="src short"><span class="keyword">data</span>  <a href="#t:StdGen">StdGen</a> </li><li class="src short"><a href="#v:mkStdGen">mkStdGen</a> :: <a href="Prelude.html#t:Int">Int</a> -&gt; <a href="Random.html#t:StdGen">StdGen</a></li><li class="src short"><a href="#v:getStdRandom">getStdRandom</a> ::  (<a href="Random.html#t:StdGen">StdGen</a> -&gt; (a, <a href="Random.html#t:StdGen">StdGen</a>)) -&gt; <a href="Prelude.html#t:IO">IO</a> a</li><li class="src short"><a href="#v:getStdGen">getStdGen</a> :: <a href="Prelude.html#t:IO">IO</a> <a href="Random.html#t:StdGen">StdGen</a></li><li class="src short"><a href="#v:setStdGen">setStdGen</a> :: <a href="Random.html#t:StdGen">StdGen</a> -&gt; <a href="Prelude.html#t:IO">IO</a> ()</li><li class="src short"><a href="#v:newStdGen">newStdGen</a> :: <a href="Prelude.html#t:IO">IO</a> <a href="Random.html#t:StdGen">StdGen</a></li><li class="src short"><span class="keyword">class</span>  <a href="#t:Random">Random</a> a  <span class="keyword">where</span><ul class="subs"><li><a href="#v:randomR">randomR</a> :: <a href="Random.html#t:RandomGen">RandomGen</a> g =&gt; (a, a) -&gt; g -&gt; (a, g)</li><li><a href="#v:random">random</a> :: <a href="Random.html#t:RandomGen">RandomGen</a> g =&gt; g -&gt; (a, g)</li><li><a href="#v:randomRs">randomRs</a> :: <a href="Random.html#t:RandomGen">RandomGen</a> g =&gt; (a, a) -&gt; g -&gt; [a]</li><li><a href="#v:randoms">randoms</a> :: <a href="Random.html#t:RandomGen">RandomGen</a> g =&gt; g -&gt; [a]</li><li><a href="#v:randomRIO">randomRIO</a> :: (a, a) -&gt; <a href="Prelude.html#t:IO">IO</a> a</li><li><a href="#v:randomIO">randomIO</a> :: <a href="Prelude.html#t:IO">IO</a> a</li></ul></li></ul></div><div id="interface"><h1 id="g:1">Random number generators
</h1><div class="top"><p class="src"><span class="keyword">class</span>  <a name="t:RandomGen" class="def">RandomGen</a> g  <span class="keyword">where</span></p><div class="doc"><p>The class <code><a href="Random.html#t:RandomGen">RandomGen</a></code> provides a common interface to random number
 generators.
</p><p>Minimal complete definition: <code><a href="Random.html#v:next">next</a></code> and <code><a href="Random.html#v:split">split</a></code>.
</p></div><div class="subs methods"><p class="caption">Methods</p><p class="src"><a name="v:next" class="def">next</a> :: g -&gt; (<a href="Prelude.html#t:Int">Int</a>, g)</p><div class="doc"><p>The <code><a href="Random.html#v:next">next</a></code> operation returns an <code><a href="Prelude.html#t:Int">Int</a></code> that is uniformly distributed
 in the range returned by <code><a href="Random.html#v:genRange">genRange</a></code> (including both end points),
 and a new generator.
</p></div><p class="src"><a name="v:split" class="def">split</a> :: g -&gt; (g, g)</p><div class="doc"><p>The <code><a href="Random.html#v:split">split</a></code> operation allows one to obtain two distinct random number
 generators. This is very useful in functional programs (for example, when
 passing a random number generator down to recursive calls), but very
 little work has been done on statistically robust implementations of
 <code><a href="Random.html#v:split">split</a></code> ([<a href="Random.html#Burton">Random</a>, <a href="Random.html#Hellekalek">Random</a>]
 are the only examples we know of).
</p></div><p class="src"><a name="v:genRange" class="def">genRange</a> :: g -&gt; (<a href="Prelude.html#t:Int">Int</a>, <a href="Prelude.html#t:Int">Int</a>)</p><div class="doc"><p>The <code><a href="Random.html#v:genRange">genRange</a></code> operation yields the range of values returned by
 the generator.
</p><p>It is required that:
</p><ul><li> If <code>(a,b) = <code><a href="Random.html#v:genRange">genRange</a></code> g</code>, then <code>a &lt; b</code>.
</li><li> <code><a href="Random.html#v:genRange">genRange</a></code> always returns a pair of defined <code><a href="Prelude.html#t:Int">Int</a></code>s.
</li></ul><p>The second condition ensures that <code><a href="Random.html#v:genRange">genRange</a></code> cannot examine its
 argument, and hence the value it returns can be determined only by the
 instance of <code><a href="Random.html#t:RandomGen">RandomGen</a></code>.  That in turn allows an implementation to make
 a single call to <code><a href="Random.html#v:genRange">genRange</a></code> to establish a generator's range, without
 being concerned that the generator returned by (say) <code><a href="Random.html#v:next">next</a></code> might have
 a different range to the generator passed to <code><a href="Random.html#v:next">next</a></code>.
</p><p>The default definition spans the full range of <code><a href="Prelude.html#t:Int">Int</a></code>.
</p></div></div><div class="subs instances"><p id="control.i:RandomGen" class="caption collapser" onclick="toggleSection('i:RandomGen')">Instances</p><div id="section.i:RandomGen" class="show"><table><tr><td class="src"><a href="Random.html#t:RandomGen">RandomGen</a> <a href="Random.html#t:StdGen">StdGen</a></td><td class="doc empty">&nbsp;</td></tr></table></div></div></div><h2 id="g:2">Standard random number generators
</h2><div class="top"><p class="src"><span class="keyword">data</span>  <a name="t:StdGen" class="def">StdGen</a>  </p><div class="doc"><p>The <code><a href="Random.html#t:StdGen">StdGen</a></code> instance of <code><a href="Random.html#t:RandomGen">RandomGen</a></code> has a <code><a href="Random.html#v:genRange">genRange</a></code> of at least 30 bits.
</p><p>The result of repeatedly using <code><a href="Random.html#v:next">next</a></code> should be at least as statistically
robust as the <em>Minimal Standard Random Number Generator</em> described by
[<a href="Random.html#Park">Random</a>, <a href="Random.html#Carta">Random</a>].
Until more is known about implementations of <code><a href="Random.html#v:split">split</a></code>, all we require is
that <code><a href="Random.html#v:split">split</a></code> deliver generators that are (a) not identical and
(b) independently robust in the sense just given.
</p><p>The <code><a href="Prelude.html#t:Show">Show</a></code> and <code><a href="Prelude.html#t:Read">Read</a></code> instances of <code><a href="Random.html#t:StdGen">StdGen</a></code> provide a primitive way to save the
state of a random number generator.
It is required that <code><code><a href="Prelude.html#v:read">read</a></code> (<code><a href="Prelude.html#v:show">show</a></code> g) == g</code>.
</p><p>In addition, <code><a href="Prelude.html#v:reads">reads</a></code> may be used to map an arbitrary string (not necessarily one
produced by <code><a href="Prelude.html#v:show">show</a></code>) onto a value of type <code><a href="Random.html#t:StdGen">StdGen</a></code>. In general, the <code><a href="Prelude.html#t:Read">Read</a></code>
instance of <code><a href="Random.html#t:StdGen">StdGen</a></code> has the following properties:
</p><ul><li> It guarantees to succeed on any string.
</li><li> It guarantees to consume only a finite portion of the string.
</li><li> Different argument strings are likely to result in different results.
</li></ul></div><div class="subs instances"><p id="control.i:StdGen" class="caption collapser" onclick="toggleSection('i:StdGen')">Instances</p><div id="section.i:StdGen" class="show"><table><tr><td class="src"><a href="Prelude.html#t:Read">Read</a> <a href="Random.html#t:StdGen">StdGen</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Prelude.html#t:Show">Show</a> <a href="Random.html#t:StdGen">StdGen</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Random.html#t:RandomGen">RandomGen</a> <a href="Random.html#t:StdGen">StdGen</a></td><td class="doc empty">&nbsp;</td></tr></table></div></div></div><div class="top"><p class="src"><a name="v:mkStdGen" class="def">mkStdGen</a> :: <a href="Prelude.html#t:Int">Int</a> -&gt; <a href="Random.html#t:StdGen">StdGen</a></p><div class="doc"><p>The function <code><a href="Random.html#v:mkStdGen">mkStdGen</a></code> provides an alternative way of producing an initial
generator, by mapping an <code><a href="Prelude.html#t:Int">Int</a></code> into a generator. Again, distinct arguments
should be likely to produce distinct generators.
</p></div></div><h2 id="g:3">The global random number generator
</h2><div class="doc"><p><a name="globalrng"></a>
</p><p>There is a single, implicit, global random number generator of type
<code><a href="Random.html#t:StdGen">StdGen</a></code>, held in some global variable maintained by the <code><a href="Prelude.html#t:IO">IO</a></code> monad. It is
initialised automatically in some system-dependent fashion, for example, by
using the time of day, or Linux's kernel random number generator. To get
deterministic behaviour, use <code><a href="Random.html#v:setStdGen">setStdGen</a></code>.
</p></div><div class="top"><p class="src"><a name="v:getStdRandom" class="def">getStdRandom</a> ::  (<a href="Random.html#t:StdGen">StdGen</a> -&gt; (a, <a href="Random.html#t:StdGen">StdGen</a>)) -&gt; <a href="Prelude.html#t:IO">IO</a> a</p><div class="doc"><p>Uses the supplied function to get a value from the current global
random generator, and updates the global generator with the new generator
returned by the function. For example, <code>rollDice</code> gets a random integer
between 1 and 6:
</p><pre>  rollDice :: IO Int
  rollDice = getStdRandom (randomR (1,6))
</pre></div></div><div class="top"><p class="src"><a name="v:getStdGen" class="def">getStdGen</a> :: <a href="Prelude.html#t:IO">IO</a> <a href="Random.html#t:StdGen">StdGen</a></p><div class="doc"><p>Gets the global random number generator.
</p></div></div><div class="top"><p class="src"><a name="v:setStdGen" class="def">setStdGen</a> :: <a href="Random.html#t:StdGen">StdGen</a> -&gt; <a href="Prelude.html#t:IO">IO</a> ()</p><div class="doc"><p>Sets the global random number generator.
</p></div></div><div class="top"><p class="src"><a name="v:newStdGen" class="def">newStdGen</a> :: <a href="Prelude.html#t:IO">IO</a> <a href="Random.html#t:StdGen">StdGen</a></p><div class="doc"><p>Applies <code><a href="Random.html#v:split">split</a></code> to the current global random generator,
 updates it with one of the results, and returns the other.
</p></div></div><h1 id="g:4">Random values of various types
</h1><div class="top"><p class="src"><span class="keyword">class</span>  <a name="t:Random" class="def">Random</a> a  <span class="keyword">where</span></p><div class="doc"><p>With a source of random number supply in hand, the <code><a href="Random.html#t:Random">Random</a></code> class allows the
programmer to extract random values of a variety of types.
</p><p>Minimal complete definition: <code><a href="Random.html#v:randomR">randomR</a></code> and <code><a href="Random.html#v:random">random</a></code>.
</p></div><div class="subs methods"><p class="caption">Methods</p><p class="src"><a name="v:randomR" class="def">randomR</a> :: <a href="Random.html#t:RandomGen">RandomGen</a> g =&gt; (a, a) -&gt; g -&gt; (a, g)</p><div class="doc"><p>Takes a range <em>(lo,hi)</em> and a random number generator
 <em>g</em>, and returns a random value uniformly distributed in the closed
 interval <em>[lo,hi]</em>, together with a new generator. It is unspecified
 what happens if <em>lo&gt;hi</em>. For continuous types there is no requirement
 that the values <em>lo</em> and <em>hi</em> are ever produced, but they may be,
 depending on the implementation and the interval.
</p></div><p class="src"><a name="v:random" class="def">random</a> :: <a href="Random.html#t:RandomGen">RandomGen</a> g =&gt; g -&gt; (a, g)</p><div class="doc"><p>The same as <code><a href="Random.html#v:randomR">randomR</a></code>, but using a default range determined by the type:
</p><ul><li> For bounded types (instances of <code><a href="Prelude.html#t:Bounded">Bounded</a></code>, such as <code><a href="Prelude.html#t:Char">Char</a></code>),
   the range is normally the whole type.
</li><li> For fractional types, the range is normally the semi-closed interval
 <code>[0,1)</code>.
</li><li> For <code><a href="Prelude.html#t:Integer">Integer</a></code>, the range is (arbitrarily) the range of <code><a href="Prelude.html#t:Int">Int</a></code>.
</li></ul></div><p class="src"><a name="v:randomRs" class="def">randomRs</a> :: <a href="Random.html#t:RandomGen">RandomGen</a> g =&gt; (a, a) -&gt; g -&gt; [a]</p><div class="doc"><p>Plural variant of <code><a href="Random.html#v:randomR">randomR</a></code>, producing an infinite list of
 random values instead of returning a new generator.
</p></div><p class="src"><a name="v:randoms" class="def">randoms</a> :: <a href="Random.html#t:RandomGen">RandomGen</a> g =&gt; g -&gt; [a]</p><div class="doc"><p>Plural variant of <code><a href="Random.html#v:random">random</a></code>, producing an infinite list of
 random values instead of returning a new generator.
</p></div><p class="src"><a name="v:randomRIO" class="def">randomRIO</a> :: (a, a) -&gt; <a href="Prelude.html#t:IO">IO</a> a</p><div class="doc"><p>A variant of <code><a href="Random.html#v:randomR">randomR</a></code> that uses the global random number generator
 (see <a href="Random.html#globalrng">Random</a>).
</p></div><p class="src"><a name="v:randomIO" class="def">randomIO</a> :: <a href="Prelude.html#t:IO">IO</a> a</p><div class="doc"><p>A variant of <code><a href="Random.html#v:random">random</a></code> that uses the global random number generator
 (see <a href="Random.html#globalrng">Random</a>).
</p></div></div><div class="subs instances"><p id="control.i:Random" class="caption collapser" onclick="toggleSection('i:Random')">Instances</p><div id="section.i:Random" class="show"><table><tr><td class="src"><a href="Random.html#t:Random">Random</a> <a href="Prelude.html#t:Bool">Bool</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Random.html#t:Random">Random</a> <a href="Prelude.html#t:Char">Char</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Random.html#t:Random">Random</a> <a href="Prelude.html#t:Double">Double</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Random.html#t:Random">Random</a> <a href="Prelude.html#t:Float">Float</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Random.html#t:Random">Random</a> <a href="Prelude.html#t:Int">Int</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Random.html#t:Random">Random</a> <a href="Prelude.html#t:Integer">Integer</a></td><td class="doc empty">&nbsp;</td></tr></table></div></div></div><h1 id="g:5">References
</h1><div class="doc"><ol><li> FW <a name="Burton"></a> Burton and RL Page, <em>Distributed random number generation</em>,
Journal of Functional Programming, 2(2):203-212, April 1992.
</li><li> SK <a name="Park"></a> Park, and KW Miller, /Random number generators -
good ones are hard to find/, Comm ACM 31(10), Oct 1988, pp1192-1201.
</li><li> DG <a name="Carta"></a> Carta, /Two fast implementations of the minimal standard
random number generator/, Comm ACM, 33(1), Jan 1990, pp87-88.
</li><li> P <a name="Hellekalek"></a> Hellekalek, <em>Don\'t trust parallel Monte Carlo</em>,
Department of Mathematics, University of Salzburg,
<a href="http://random.mat.sbg.ac.at/~peter/pads98.ps">http://random.mat.sbg.ac.at/~peter/pads98.ps</a>, 1998.
</li><li> Pierre <a name="LEcuyer"></a> L'Ecuyer, /Efficient and portable combined random
number generators/, Comm ACM, 31(6), Jun 1988, pp742-749.
</li></ol><p>The Web site <a href="http://random.mat.sbg.ac.at/">http://random.mat.sbg.ac.at/</a> is a great source of information.
</p></div></div></div><div id="footer"><p>Produced by <a href="http://www.haskell.org/haddock/">Haddock</a> version 2.11.0</p></div></body></html>