Sophie

Sophie

distrib > Fedora > 15 > i386 > by-pkgid > d15443065881701e38c53c7ecf9d664b > files > 90

ghc-haskell98-devel-1.1.0.1-16.fc15.i686.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="src/Random.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">haskell98-1.1.0.1: Compatibility with Haskell 98</p></div><div id="content"><div id="module-header"><p class="caption">Random</p></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="../base-4.3.1.0/Data-Int.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="../base-4.3.1.0/Data-Int.html#t:Int">Int</a>, <a href="../base-4.3.1.0/Data-Int.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="../base-4.3.1.0/Data-Int.html#t:Int">Int</a> -&gt; <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="IO.html#t:IO">IO</a> a</li><li><a href="#v:randomIO">randomIO</a> :: <a href="IO.html#t:IO">IO</a> a</li></ul></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="IO.html#t:IO">IO</a> a</li><li class="src short"><a href="#v:getStdGen">getStdGen</a> :: <a href="IO.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="IO.html#t:IO">IO</a> ()</li><li class="src short"><a href="#v:newStdGen">newStdGen</a> :: <a href="IO.html#t:IO">IO</a> <a href="Random.html#t:StdGen">StdGen</a></li></ul></div><div id="interface"><h1>Documentation</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><a href="../random-1.0.0.3/src/System-Random.html#RandomGen" class="link">Source</a></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="../base-4.3.1.0/Data-Int.html#t:Int">Int</a>, g)<a href="../random-1.0.0.3/src/System-Random.html#next" class="link">Source</a></p><div class="doc"><p>The <code><a href="Random.html#v:next">next</a></code> operation returns an <code><a href="../base-4.3.1.0/Data-Int.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)<a href="../random-1.0.0.3/src/System-Random.html#split" class="link">Source</a></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="System-Random.html#Burton">System.Random</a>, <a href="System-Random.html#Hellekalek">System.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="../base-4.3.1.0/Data-Int.html#t:Int">Int</a>, <a href="../base-4.3.1.0/Data-Int.html#t:Int">Int</a>)<a href="../random-1.0.0.3/src/System-Random.html#genRange" class="link">Source</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="../base-4.3.1.0/Data-Int.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="../base-4.3.1.0/Data-Int.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><div class="top"><p class="src"><span class="keyword">data</span>  <a name="t:StdGen" class="def">StdGen</a>  <a href="../random-1.0.0.3/src/System-Random.html#StdGen" class="link">Source</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="System-Random.html#Park">System.Random</a>, <a href="System-Random.html#Carta">System.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="../base-4.3.1.0/Text-Show.html#t:Show">Show</a></code> and <code><a href="../base-4.3.1.0/Text-Read.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="../base-4.3.1.0/Text-Read.html#v:read">read</a></code> (<code><a href="../base-4.3.1.0/Text-Show.html#v:show">show</a></code> g) == g</code>.
</p><p>In addition, <code><a href="../base-4.3.1.0/Text-Read.html#v:reads">reads</a></code> may be used to map an arbitrary string (not necessarily one
produced by <code><a href="../base-4.3.1.0/Text-Show.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="../base-4.3.1.0/Text-Read.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="../base-4.3.1.0/Text-Read.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="../base-4.3.1.0/Text-Show.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="../base-4.3.1.0/Data-Int.html#t:Int">Int</a> -&gt; <a href="Random.html#t:StdGen">StdGen</a><a href="../random-1.0.0.3/src/System-Random.html#mkStdGen" class="link">Source</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="../base-4.3.1.0/Data-Int.html#t:Int">Int</a></code> into a generator. Again, distinct arguments
should be likely to produce distinct generators.
</p></div></div><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><a href="../random-1.0.0.3/src/System-Random.html#Random" class="link">Source</a></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)<a href="../random-1.0.0.3/src/System-Random.html#randomR" class="link">Source</a></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)<a href="../random-1.0.0.3/src/System-Random.html#random" class="link">Source</a></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="../base-4.3.1.0/Prelude.html#t:Bounded">Bounded</a></code>, such as <code><a href="Char.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="../base-4.3.1.0/Prelude.html#t:Integer">Integer</a></code>, the range is (arbitrarily) the range of <code><a href="../base-4.3.1.0/Data-Int.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]<a href="../random-1.0.0.3/src/System-Random.html#randomRs" class="link">Source</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]<a href="../random-1.0.0.3/src/System-Random.html#randoms" class="link">Source</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="IO.html#t:IO">IO</a> a<a href="../random-1.0.0.3/src/System-Random.html#randomRIO" class="link">Source</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="System-Random.html#globalrng">System.Random</a>).
</p></div><p class="src"><a name="v:randomIO" class="def">randomIO</a> :: <a href="IO.html#t:IO">IO</a> a<a href="../random-1.0.0.3/src/System-Random.html#randomIO" class="link">Source</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="System-Random.html#globalrng">System.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="../base-4.3.1.0/Data-Bool.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="Char.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="../base-4.3.1.0/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="../base-4.3.1.0/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="../base-4.3.1.0/Data-Int.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="../base-4.3.1.0/Prelude.html#t:Integer">Integer</a></td><td class="doc empty">&nbsp;</td></tr></table></div></div></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="IO.html#t:IO">IO</a> a<a href="../random-1.0.0.3/src/System-Random.html#getStdRandom" class="link">Source</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="IO.html#t:IO">IO</a> <a href="Random.html#t:StdGen">StdGen</a><a href="../random-1.0.0.3/src/System-Random.html#getStdGen" class="link">Source</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="IO.html#t:IO">IO</a> ()<a href="../random-1.0.0.3/src/System-Random.html#setStdGen" class="link">Source</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="IO.html#t:IO">IO</a> <a href="Random.html#t:StdGen">StdGen</a><a href="../random-1.0.0.3/src/System-Random.html#newStdGen" class="link">Source</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></div></div><div id="footer"><p>Produced by <a href="http://www.haskell.org/haddock/">Haddock</a> version 2.9.2</p></div></body></html>