<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <!--Rendered using the Haskell Html Library v0.2--> <HTML ><HEAD ><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8" ><TITLE >System.Random</TITLE ><LINK HREF="haddock.css" REL="stylesheet" TYPE="text/css" ><SCRIPT SRC="haddock-util.js" TYPE="text/javascript" ></SCRIPT ><SCRIPT TYPE="text/javascript" >window.onload = function () {setSynopsis("mini_System-Random.html")};</SCRIPT ></HEAD ><BODY ><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0" ><TR ><TD CLASS="topbar" ><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0" ><TR ><TD ><IMG SRC="haskell_icon.gif" WIDTH="16" HEIGHT="16" ALT=" " ></TD ><TD CLASS="title" >random-1.0.0.1: random number library</TD ><TD CLASS="topbut" ><A HREF="index.html" >Contents</A ></TD ><TD CLASS="topbut" ><A HREF="doc-index.html" >Index</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="modulebar" ><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0" ><TR ><TD ><FONT SIZE="6" >System.Random</FONT ></TD ><TD ALIGN="right" ><TABLE CLASS="narrow" CELLSPACING="0" CELLPADDING="0" ><TR ><TD CLASS="infohead" >Portability</TD ><TD CLASS="infoval" >portable</TD ></TR ><TR ><TD CLASS="infohead" >Stability</TD ><TD CLASS="infoval" >stable</TD ></TR ><TR ><TD CLASS="infohead" >Maintainer</TD ><TD CLASS="infoval" >libraries@haskell.org</TD ></TR ></TABLE ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD ><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0" ><TR ><TD CLASS="section4" ><B >Contents</B ></TD ></TR ><TR ><TD ><DL ><DT ><A HREF="#1" >Random number generators </A ></DT ><DD ><DL ><DT ><A HREF="#2" >Standard random number generators </A ></DT ><DT ><A HREF="#3" >The global random number generator </A ></DT ></DL ></DD ><DT ><A HREF="#4" >Random values of various types </A ></DT ><DT ><A HREF="#5" >References </A ></DT ></DL ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="section1" >Description</TD ></TR ><TR ><TD CLASS="doc" ><P >This library deals with the common task of pseudo-random number generation. The library makes it possible to generate repeatable results, by starting with a specified initial random number generator, or to get different results on each run by using the system-initialised generator or by supplying a seed from some other source. </P ><P >The library is split into two layers: </P ><UL ><LI > A core <EM >random number generator</EM > provides a supply of bits. The class <TT ><A HREF="System-Random.html#t%3ARandomGen" >RandomGen</A ></TT > provides a common interface to such generators. The library provides one instance of <TT ><A HREF="System-Random.html#t%3ARandomGen" >RandomGen</A ></TT >, the abstract data type <TT ><A HREF="System-Random.html#t%3AStdGen" >StdGen</A ></TT >. Programmers may, of course, supply their own instances of <TT ><A HREF="System-Random.html#t%3ARandomGen" >RandomGen</A ></TT >. </LI ><LI > The class <TT ><A HREF="System-Random.html#t%3ARandom" >Random</A ></TT > provides a way to extract values of a particular type from a random number generator. For example, the <TT ><A HREF="../ghc-prim/GHC-Types.html#t%3AFloat" >Float</A ></TT > instance of <TT ><A HREF="System-Random.html#t%3ARandom" >Random</A ></TT > allows one to generate random values of type <TT ><A HREF="../ghc-prim/GHC-Types.html#t%3AFloat" >Float</A ></TT >. </LI ></UL ><P >This implementation uses the Portable Combined Generator of L'Ecuyer [<A HREF="System-Random.html#LEcuyer" >System.Random</A >] for 32-bit computers, transliterated by Lennart Augustsson. It has a period of roughly 2.30584e18. </P ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="section1" >Synopsis</TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="body" ><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0" ><TR ><TD CLASS="decl" ><SPAN CLASS="keyword" >class</SPAN > <A HREF="#t%3ARandomGen" >RandomGen</A > g <SPAN CLASS="keyword" >where</SPAN ></TD ></TR ><TR ><TD CLASS="body" ><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0" ><TR ><TD CLASS="decl" ><A HREF="#v%3Anext" >next</A > :: g -> (<A HREF="../ghc-prim/GHC-Types.html#t%3AInt" >Int</A >, g)</TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Asplit" >split</A > :: g -> (g, g)</TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AgenRange" >genRange</A > :: g -> (<A HREF="../ghc-prim/GHC-Types.html#t%3AInt" >Int</A >, <A HREF="../ghc-prim/GHC-Types.html#t%3AInt" >Int</A >)</TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><SPAN CLASS="keyword" >data</SPAN > <A HREF="#t%3AStdGen" >StdGen</A > </TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AmkStdGen" >mkStdGen</A > :: <A HREF="../ghc-prim/GHC-Types.html#t%3AInt" >Int</A > -> <A HREF="System-Random.html#t%3AStdGen" >StdGen</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AgetStdRandom" >getStdRandom</A > :: (<A HREF="System-Random.html#t%3AStdGen" >StdGen</A > -> (a, <A HREF="System-Random.html#t%3AStdGen" >StdGen</A >)) -> <A HREF="../base/System-IO.html#t%3AIO" >IO</A > a</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AgetStdGen" >getStdGen</A > :: <A HREF="../base/System-IO.html#t%3AIO" >IO</A > <A HREF="System-Random.html#t%3AStdGen" >StdGen</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AsetStdGen" >setStdGen</A > :: <A HREF="System-Random.html#t%3AStdGen" >StdGen</A > -> <A HREF="../base/System-IO.html#t%3AIO" >IO</A > <A HREF="../ghc-prim/GHC-Unit.html#t%3A%28%29" >()</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AnewStdGen" >newStdGen</A > :: <A HREF="../base/System-IO.html#t%3AIO" >IO</A > <A HREF="System-Random.html#t%3AStdGen" >StdGen</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><SPAN CLASS="keyword" >class</SPAN > <A HREF="#t%3ARandom" >Random</A > a <SPAN CLASS="keyword" >where</SPAN ></TD ></TR ><TR ><TD CLASS="body" ><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0" ><TR ><TD CLASS="decl" ><A HREF="#v%3ArandomR" >randomR</A > :: <A HREF="System-Random.html#t%3ARandomGen" >RandomGen</A > g => (a, a) -> g -> (a, g)</TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Arandom" >random</A > :: <A HREF="System-Random.html#t%3ARandomGen" >RandomGen</A > g => g -> (a, g)</TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3ArandomRs" >randomRs</A > :: <A HREF="System-Random.html#t%3ARandomGen" >RandomGen</A > g => (a, a) -> g -> [a]</TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Arandoms" >randoms</A > :: <A HREF="System-Random.html#t%3ARandomGen" >RandomGen</A > g => g -> [a]</TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3ArandomRIO" >randomRIO</A > :: (a, a) -> <A HREF="../base/System-IO.html#t%3AIO" >IO</A > a</TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3ArandomIO" >randomIO</A > :: <A HREF="../base/System-IO.html#t%3AIO" >IO</A > a</TD ></TR ></TABLE ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="section1" ><A NAME="1" ><A NAME="1" >Random number generators </A ></A ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><SPAN CLASS="keyword" >class</SPAN > <A NAME="t:RandomGen" ><A NAME="t%3ARandomGen" ></A ></A ><B >RandomGen</B > g <SPAN CLASS="keyword" >where</SPAN ></TD ></TR ><TR ><TD CLASS="body" ><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0" ><TR ><TD CLASS="ndoc" ><P >The class <TT ><A HREF="System-Random.html#t%3ARandomGen" >RandomGen</A ></TT > provides a common interface to random number generators. </P ><P >Minimal complete definition: <TT ><A HREF="System-Random.html#v%3Anext" >next</A ></TT > and <TT ><A HREF="System-Random.html#v%3Asplit" >split</A ></TT >. </P ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="section4" >Methods</TD ></TR ><TR ><TD CLASS="body" ><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0" ><TR ><TD CLASS="decl" ><A NAME="v:next" ><A NAME="v%3Anext" ></A ></A ><B >next</B > :: g -> (<A HREF="../ghc-prim/GHC-Types.html#t%3AInt" >Int</A >, g)</TD ></TR ><TR ><TD CLASS="doc" >The <TT ><A HREF="System-Random.html#v%3Anext" >next</A ></TT > operation returns an <TT ><A HREF="../ghc-prim/GHC-Types.html#t%3AInt" >Int</A ></TT > that is uniformly distributed in the range returned by <TT ><A HREF="System-Random.html#v%3AgenRange" >genRange</A ></TT > (including both end points), and a new generator. </TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:split" ><A NAME="v%3Asplit" ></A ></A ><B >split</B > :: g -> (g, g)</TD ></TR ><TR ><TD CLASS="doc" >The <TT ><A HREF="System-Random.html#v%3Asplit" >split</A ></TT > 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 <TT ><A HREF="System-Random.html#v%3Asplit" >split</A ></TT > ([<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). </TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:genRange" ><A NAME="v%3AgenRange" ></A ></A ><B >genRange</B > :: g -> (<A HREF="../ghc-prim/GHC-Types.html#t%3AInt" >Int</A >, <A HREF="../ghc-prim/GHC-Types.html#t%3AInt" >Int</A >)</TD ></TR ><TR ><TD CLASS="doc" ><P >The <TT ><A HREF="System-Random.html#v%3AgenRange" >genRange</A ></TT > operation yields the range of values returned by the generator. </P ><P >It is required that: </P ><UL ><LI > If <TT >(a,b) = <TT ><A HREF="System-Random.html#v%3AgenRange" >genRange</A ></TT > g</TT >, then <TT >a < b</TT >. </LI ><LI > <TT ><A HREF="System-Random.html#v%3AgenRange" >genRange</A ></TT > always returns a pair of defined <TT ><A HREF="../ghc-prim/GHC-Types.html#t%3AInt" >Int</A ></TT >s. </LI ></UL ><P >The second condition ensures that <TT ><A HREF="System-Random.html#v%3AgenRange" >genRange</A ></TT > cannot examine its argument, and hence the value it returns can be determined only by the instance of <TT ><A HREF="System-Random.html#t%3ARandomGen" >RandomGen</A ></TT >. That in turn allows an implementation to make a single call to <TT ><A HREF="System-Random.html#v%3AgenRange" >genRange</A ></TT > to establish a generator's range, without being concerned that the generator returned by (say) <TT ><A HREF="System-Random.html#v%3Anext" >next</A ></TT > might have a different range to the generator passed to <TT ><A HREF="System-Random.html#v%3Anext" >next</A ></TT >. </P ><P >The default definition spans the full range of <TT ><A HREF="../ghc-prim/GHC-Types.html#t%3AInt" >Int</A ></TT >. </P ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="section4" ><IMG SRC="minus.gif" CLASS="coll" ONCLICK="toggle(this,'i:RandomGen')" ALT="show/hide" > Instances</TD ></TR ><TR ><TD CLASS="body" ><DIV ID="i:RandomGen" STYLE="display:block;" ><TABLE CLASS="vanilla" CELLSPACING="1" CELLPADDING="0" ><TR ><TD CLASS="decl" ><A HREF="System-Random.html#t%3ARandomGen" >RandomGen</A > <A HREF="System-Random.html#t%3AStdGen" >StdGen</A ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="section2" ><A NAME="2" ><A NAME="2" >Standard random number generators </A ></A ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><SPAN CLASS="keyword" >data</SPAN > <A NAME="t:StdGen" ><A NAME="t%3AStdGen" ></A ></A ><B >StdGen</B > </TD ></TR ><TR ><TD CLASS="body" ><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0" ><TR ><TD CLASS="ndoc" ><P >The <TT ><A HREF="System-Random.html#t%3AStdGen" >StdGen</A ></TT > instance of <TT ><A HREF="System-Random.html#t%3ARandomGen" >RandomGen</A ></TT > has a <TT ><A HREF="System-Random.html#v%3AgenRange" >genRange</A ></TT > of at least 30 bits. </P ><P >The result of repeatedly using <TT ><A HREF="System-Random.html#v%3Anext" >next</A ></TT > 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 <TT ><A HREF="System-Random.html#v%3Asplit" >split</A ></TT >, all we require is that <TT ><A HREF="System-Random.html#v%3Asplit" >split</A ></TT > deliver generators that are (a) not identical and (b) independently robust in the sense just given. </P ><P >The <TT ><A HREF="../base/Text-Show.html#t%3AShow" >Show</A ></TT > and <TT ><A HREF="../base/Text-Read.html#t%3ARead" >Read</A ></TT > instances of <TT ><A HREF="System-Random.html#t%3AStdGen" >StdGen</A ></TT > provide a primitive way to save the state of a random number generator. It is required that <TT ><TT ><A HREF="../base/Text-Read.html#v%3Aread" >read</A ></TT > (<TT ><A HREF="../base/Text-Show.html#v%3Ashow" >show</A ></TT > g) == g</TT >. </P ><P >In addition, <TT ><A HREF="../base/Text-Read.html#v%3Aread" >read</A ></TT > may be used to map an arbitrary string (not necessarily one produced by <TT ><A HREF="../base/Text-Show.html#v%3Ashow" >show</A ></TT >) onto a value of type <TT ><A HREF="System-Random.html#t%3AStdGen" >StdGen</A ></TT >. In general, the <TT ><A HREF="../base/Text-Read.html#v%3Aread" >read</A ></TT > instance of <TT ><A HREF="System-Random.html#t%3AStdGen" >StdGen</A ></TT > 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 ></TD ></TR ><TR ><TD CLASS="section4" ><IMG SRC="minus.gif" CLASS="coll" ONCLICK="toggle(this,'i:StdGen')" ALT="show/hide" > Instances</TD ></TR ><TR ><TD CLASS="body" ><DIV ID="i:StdGen" STYLE="display:block;" ><TABLE CLASS="vanilla" CELLSPACING="1" CELLPADDING="0" ><TR ><TD CLASS="decl" ><A HREF="../base/Text-Read.html#t%3ARead" >Read</A > <A HREF="System-Random.html#t%3AStdGen" >StdGen</A ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="../base/Text-Show.html#t%3AShow" >Show</A > <A HREF="System-Random.html#t%3AStdGen" >StdGen</A ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="System-Random.html#t%3ARandomGen" >RandomGen</A > <A HREF="System-Random.html#t%3AStdGen" >StdGen</A ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:mkStdGen" ><A NAME="v%3AmkStdGen" ></A ></A ><B >mkStdGen</B > :: <A HREF="../ghc-prim/GHC-Types.html#t%3AInt" >Int</A > -> <A HREF="System-Random.html#t%3AStdGen" >StdGen</A ></TD ></TR ><TR ><TD CLASS="doc" >The function <TT ><A HREF="System-Random.html#v%3AmkStdGen" >mkStdGen</A ></TT > provides an alternative way of producing an initial generator, by mapping an <TT ><A HREF="../ghc-prim/GHC-Types.html#t%3AInt" >Int</A ></TT > into a generator. Again, distinct arguments should be likely to produce distinct generators. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="section2" ><A NAME="3" ><A NAME="3" >The global random number generator </A ></A ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="doc" ><P ><A NAME="globalrng" ><A NAME="globalrng" ></A ></A > </P ><P >There is a single, implicit, global random number generator of type <TT ><A HREF="System-Random.html#t%3AStdGen" >StdGen</A ></TT >, held in some global variable maintained by the <TT ><A HREF="../base/System-IO.html#t%3AIO" >IO</A ></TT > 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 <TT ><A HREF="System-Random.html#v%3AsetStdGen" >setStdGen</A ></TT >. </P ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:getStdRandom" ><A NAME="v%3AgetStdRandom" ></A ></A ><B >getStdRandom</B > :: (<A HREF="System-Random.html#t%3AStdGen" >StdGen</A > -> (a, <A HREF="System-Random.html#t%3AStdGen" >StdGen</A >)) -> <A HREF="../base/System-IO.html#t%3AIO" >IO</A > a</TD ></TR ><TR ><TD 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, <TT >rollDice</TT > gets a random integer between 1 and 6: </P ><PRE > rollDice :: IO Int rollDice = getStdRandom (randomR (1,6)) </PRE ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:getStdGen" ><A NAME="v%3AgetStdGen" ></A ></A ><B >getStdGen</B > :: <A HREF="../base/System-IO.html#t%3AIO" >IO</A > <A HREF="System-Random.html#t%3AStdGen" >StdGen</A ></TD ></TR ><TR ><TD CLASS="doc" >Gets the global random number generator. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:setStdGen" ><A NAME="v%3AsetStdGen" ></A ></A ><B >setStdGen</B > :: <A HREF="System-Random.html#t%3AStdGen" >StdGen</A > -> <A HREF="../base/System-IO.html#t%3AIO" >IO</A > <A HREF="../ghc-prim/GHC-Unit.html#t%3A%28%29" >()</A ></TD ></TR ><TR ><TD CLASS="doc" >Sets the global random number generator. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:newStdGen" ><A NAME="v%3AnewStdGen" ></A ></A ><B >newStdGen</B > :: <A HREF="../base/System-IO.html#t%3AIO" >IO</A > <A HREF="System-Random.html#t%3AStdGen" >StdGen</A ></TD ></TR ><TR ><TD CLASS="doc" >Applies <TT ><A HREF="System-Random.html#v%3Asplit" >split</A ></TT > to the current global random generator, updates it with one of the results, and returns the other. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="section1" ><A NAME="4" ><A NAME="4" >Random values of various types </A ></A ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><SPAN CLASS="keyword" >class</SPAN > <A NAME="t:Random" ><A NAME="t%3ARandom" ></A ></A ><B >Random</B > a <SPAN CLASS="keyword" >where</SPAN ></TD ></TR ><TR ><TD CLASS="body" ><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0" ><TR ><TD CLASS="ndoc" ><P >With a source of random number supply in hand, the <TT ><A HREF="System-Random.html#t%3ARandom" >Random</A ></TT > class allows the programmer to extract random values of a variety of types. </P ><P >Minimal complete definition: <TT ><A HREF="System-Random.html#v%3ArandomR" >randomR</A ></TT > and <TT ><A HREF="System-Random.html#v%3Arandom" >random</A ></TT >. </P ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="section4" >Methods</TD ></TR ><TR ><TD CLASS="body" ><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0" ><TR ><TD CLASS="decl" ><A NAME="v:randomR" ><A NAME="v%3ArandomR" ></A ></A ><B >randomR</B > :: <A HREF="System-Random.html#t%3ARandomGen" >RandomGen</A > g => (a, a) -> g -> (a, g)</TD ></TR ><TR ><TD CLASS="doc" >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>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. </TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:random" ><A NAME="v%3Arandom" ></A ></A ><B >random</B > :: <A HREF="System-Random.html#t%3ARandomGen" >RandomGen</A > g => g -> (a, g)</TD ></TR ><TR ><TD CLASS="doc" ><P >The same as <TT ><A HREF="System-Random.html#v%3ArandomR" >randomR</A ></TT >, but using a default range determined by the type: </P ><UL ><LI > For bounded types (instances of <TT ><A HREF="../base/Prelude.html#t%3ABounded" >Bounded</A ></TT >, such as <TT ><A HREF="../ghc-prim/GHC-Types.html#t%3AChar" >Char</A ></TT >), the range is normally the whole type. </LI ><LI > For fractional types, the range is normally the semi-closed interval <TT >[0,1)</TT >. </LI ><LI > For <TT ><A HREF="../integer/GHC-Integer.html#t%3AInteger" >Integer</A ></TT >, the range is (arbitrarily) the range of <TT ><A HREF="../ghc-prim/GHC-Types.html#t%3AInt" >Int</A ></TT >. </LI ></UL ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:randomRs" ><A NAME="v%3ArandomRs" ></A ></A ><B >randomRs</B > :: <A HREF="System-Random.html#t%3ARandomGen" >RandomGen</A > g => (a, a) -> g -> [a]</TD ></TR ><TR ><TD CLASS="doc" >Plural variant of <TT ><A HREF="System-Random.html#v%3ArandomR" >randomR</A ></TT >, producing an infinite list of random values instead of returning a new generator. </TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:randoms" ><A NAME="v%3Arandoms" ></A ></A ><B >randoms</B > :: <A HREF="System-Random.html#t%3ARandomGen" >RandomGen</A > g => g -> [a]</TD ></TR ><TR ><TD CLASS="doc" >Plural variant of <TT ><A HREF="System-Random.html#v%3Arandom" >random</A ></TT >, producing an infinite list of random values instead of returning a new generator. </TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:randomRIO" ><A NAME="v%3ArandomRIO" ></A ></A ><B >randomRIO</B > :: (a, a) -> <A HREF="../base/System-IO.html#t%3AIO" >IO</A > a</TD ></TR ><TR ><TD CLASS="doc" >A variant of <TT ><A HREF="System-Random.html#v%3ArandomR" >randomR</A ></TT > that uses the global random number generator (see <A HREF="System-Random.html#globalrng" >System.Random</A >). </TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:randomIO" ><A NAME="v%3ArandomIO" ></A ></A ><B >randomIO</B > :: <A HREF="../base/System-IO.html#t%3AIO" >IO</A > a</TD ></TR ><TR ><TD CLASS="doc" >A variant of <TT ><A HREF="System-Random.html#v%3Arandom" >random</A ></TT > that uses the global random number generator (see <A HREF="System-Random.html#globalrng" >System.Random</A >). </TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="section4" ><IMG SRC="minus.gif" CLASS="coll" ONCLICK="toggle(this,'i:Random')" ALT="show/hide" > Instances</TD ></TR ><TR ><TD CLASS="body" ><DIV ID="i:Random" STYLE="display:block;" ><TABLE CLASS="vanilla" CELLSPACING="1" CELLPADDING="0" ><TR ><TD CLASS="decl" ><A HREF="System-Random.html#t%3ARandom" >Random</A > <A HREF="../ghc-prim/GHC-Bool.html#t%3ABool" >Bool</A ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="System-Random.html#t%3ARandom" >Random</A > <A HREF="../ghc-prim/GHC-Types.html#t%3AChar" >Char</A ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="System-Random.html#t%3ARandom" >Random</A > <A HREF="../ghc-prim/GHC-Types.html#t%3ADouble" >Double</A ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="System-Random.html#t%3ARandom" >Random</A > <A HREF="../ghc-prim/GHC-Types.html#t%3AFloat" >Float</A ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="System-Random.html#t%3ARandom" >Random</A > <A HREF="../ghc-prim/GHC-Types.html#t%3AInt" >Int</A ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="System-Random.html#t%3ARandom" >Random</A > <A HREF="../integer/GHC-Integer.html#t%3AInteger" >Integer</A ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="section1" ><A NAME="5" ><A NAME="5" >References </A ></A ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="doc" ><P >1. FW <A NAME="Burton" ><A NAME="Burton" ></A ></A > Burton and RL Page, <EM >Distributed random number generation</EM >, Journal of Functional Programming, 2(2):203-212, April 1992. </P ><P >2. SK <A NAME="Park" ><A NAME="Park" ></A ></A > Park, and KW Miller, /Random number generators - good ones are hard to find/, Comm ACM 31(10), Oct 1988, pp1192-1201. </P ><P >3. DG <A NAME="Carta" ><A NAME="Carta" ></A ></A > Carta, /Two fast implementations of the minimal standard random number generator/, Comm ACM, 33(1), Jan 1990, pp87-88. </P ><P >4. P <A NAME="Hellekalek" ><A NAME="Hellekalek" ></A ></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. </P ><P >5. Pierre <A NAME="LEcuyer" ><A NAME="LEcuyer" ></A ></A > L'Ecuyer, /Efficient and portable combined random number generators/, Comm ACM, 31(6), Jun 1988, pp742-749. </P ><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 ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="botbar" >Produced by <A HREF="http://www.haskell.org/haddock/" >Haddock</A > version 2.4.2</TD ></TR ></TABLE ></BODY ></HTML >