<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <link rel="stylesheet" href="style.css" type="text/css"> <meta content="text/html; charset=iso-8859-1" http-equiv="Content-Type"> <link rel="Start" href="index.html"> <link rel="previous" href="Batteries.Queue.html"> <link rel="next" href="Batteries.Scanf.html"> <link rel="Up" href="Batteries.html"> <link title="Index of types" rel=Appendix href="index_types.html"> <link title="Index of exceptions" rel=Appendix href="index_exceptions.html"> <link title="Index of values" rel=Appendix href="index_values.html"> <link title="Index of class methods" rel=Appendix href="index_methods.html"> <link title="Index of classes" rel=Appendix href="index_classes.html"> <link title="Index of modules" rel=Appendix href="index_modules.html"> <link title="Index of module types" rel=Appendix href="index_module_types.html"> <link title="BatArray" rel="Chapter" href="BatArray.html"> <link title="BatAvlTree" rel="Chapter" href="BatAvlTree.html"> <link title="BatBase64" rel="Chapter" href="BatBase64.html"> <link title="BatBig_int" rel="Chapter" href="BatBig_int.html"> <link title="BatBigarray" rel="Chapter" href="BatBigarray.html"> <link title="BatBitSet" rel="Chapter" href="BatBitSet.html"> <link title="BatBool" rel="Chapter" href="BatBool.html"> <link title="BatBounded" rel="Chapter" href="BatBounded.html"> <link title="BatBuffer" rel="Chapter" href="BatBuffer.html"> <link title="BatCache" rel="Chapter" href="BatCache.html"> <link title="BatChar" rel="Chapter" href="BatChar.html"> <link title="BatCharParser" rel="Chapter" href="BatCharParser.html"> <link title="BatComplex" rel="Chapter" href="BatComplex.html"> <link title="BatConcurrent" rel="Chapter" href="BatConcurrent.html"> <link title="BatDeque" rel="Chapter" href="BatDeque.html"> <link title="BatDigest" rel="Chapter" href="BatDigest.html"> <link title="BatDllist" rel="Chapter" href="BatDllist.html"> <link title="BatDynArray" rel="Chapter" href="BatDynArray.html"> <link title="BatEnum" rel="Chapter" href="BatEnum.html"> <link title="BatFile" rel="Chapter" href="BatFile.html"> <link title="BatFingerTree" rel="Chapter" href="BatFingerTree.html"> <link title="BatFloat" rel="Chapter" href="BatFloat.html"> <link title="BatFormat" rel="Chapter" href="BatFormat.html"> <link title="BatGc" rel="Chapter" href="BatGc.html"> <link title="BatGenlex" rel="Chapter" href="BatGenlex.html"> <link title="BatGlobal" rel="Chapter" href="BatGlobal.html"> <link title="BatHashcons" rel="Chapter" href="BatHashcons.html"> <link title="BatHashtbl" rel="Chapter" href="BatHashtbl.html"> <link title="BatHeap" rel="Chapter" href="BatHeap.html"> <link title="BatIMap" rel="Chapter" href="BatIMap.html"> <link title="BatIO" rel="Chapter" href="BatIO.html"> <link title="BatISet" rel="Chapter" href="BatISet.html"> <link title="BatInnerIO" rel="Chapter" href="BatInnerIO.html"> <link title="BatInnerPervasives" rel="Chapter" href="BatInnerPervasives.html"> <link title="BatInnerWeaktbl" rel="Chapter" href="BatInnerWeaktbl.html"> <link title="BatInt" rel="Chapter" href="BatInt.html"> <link title="BatInt32" rel="Chapter" href="BatInt32.html"> <link title="BatInt64" rel="Chapter" href="BatInt64.html"> <link title="BatInterfaces" rel="Chapter" href="BatInterfaces.html"> <link title="BatLazyList" rel="Chapter" href="BatLazyList.html"> <link title="BatLexing" rel="Chapter" href="BatLexing.html"> <link title="BatList" rel="Chapter" href="BatList.html"> <link title="BatLog" rel="Chapter" href="BatLog.html"> <link title="BatLogger" rel="Chapter" href="BatLogger.html"> <link title="BatMap" rel="Chapter" href="BatMap.html"> <link title="BatMarshal" rel="Chapter" href="BatMarshal.html"> <link title="BatMultiMap" rel="Chapter" href="BatMultiMap.html"> <link title="BatMultiPMap" rel="Chapter" href="BatMultiPMap.html"> <link title="BatMutex" rel="Chapter" href="BatMutex.html"> <link title="BatNativeint" rel="Chapter" href="BatNativeint.html"> <link title="BatNum" rel="Chapter" href="BatNum.html"> <link title="BatNumber" rel="Chapter" href="BatNumber.html"> <link title="BatOo" rel="Chapter" href="BatOo.html"> <link title="BatOptParse" rel="Chapter" href="BatOptParse.html"> <link title="BatOption" rel="Chapter" href="BatOption.html"> <link title="BatOrd" rel="Chapter" href="BatOrd.html"> <link title="BatParserCo" rel="Chapter" href="BatParserCo.html"> <link title="BatPathGen" rel="Chapter" href="BatPathGen.html"> <link title="BatPervasives" rel="Chapter" href="BatPervasives.html"> <link title="BatPrintexc" rel="Chapter" href="BatPrintexc.html"> <link title="BatPrintf" rel="Chapter" href="BatPrintf.html"> <link title="BatQueue" rel="Chapter" href="BatQueue.html"> <link title="BatRMutex" rel="Chapter" href="BatRMutex.html"> <link title="BatRandom" rel="Chapter" href="BatRandom.html"> <link title="BatRef" rel="Chapter" href="BatRef.html"> <link title="BatRefList" rel="Chapter" href="BatRefList.html"> <link title="BatResult" rel="Chapter" href="BatResult.html"> <link title="BatReturn" rel="Chapter" href="BatReturn.html"> <link title="BatScanf" rel="Chapter" href="BatScanf.html"> <link title="BatSeq" rel="Chapter" href="BatSeq.html"> <link title="BatSet" rel="Chapter" href="BatSet.html"> <link title="BatSplay" rel="Chapter" href="BatSplay.html"> <link title="BatStack" rel="Chapter" href="BatStack.html"> <link title="BatStream" rel="Chapter" href="BatStream.html"> <link title="BatString" rel="Chapter" href="BatString.html"> <link title="BatSubstring" rel="Chapter" href="BatSubstring.html"> <link title="BatSys" rel="Chapter" href="BatSys.html"> <link title="BatText" rel="Chapter" href="BatText.html"> <link title="BatTuple" rel="Chapter" href="BatTuple.html"> <link title="BatUChar" rel="Chapter" href="BatUChar.html"> <link title="BatUTF8" rel="Chapter" href="BatUTF8.html"> <link title="BatUnit" rel="Chapter" href="BatUnit.html"> <link title="BatUnix" rel="Chapter" href="BatUnix.html"> <link title="BatUref" rel="Chapter" href="BatUref.html"> <link title="BatVect" rel="Chapter" href="BatVect.html"> <link title="Batteries" rel="Chapter" href="Batteries.html"> <link title="BatteriesConfig" rel="Chapter" href="BatteriesConfig.html"> <link title="BatteriesPrint" rel="Chapter" href="BatteriesPrint.html"> <link title="BatteriesThread" rel="Chapter" href="BatteriesThread.html"> <link title="Extlib" rel="Chapter" href="Extlib.html"><link title="Basic functions" rel="Section" href="#6_Basicfunctions"> <link title="Enumerations of random values." rel="Section" href="#6_Enumerationsofrandomvalues"> <link title="Working with data structures." rel="Section" href="#6_Workingwithdatastructures"> <link title="Advanced functions" rel="Section" href="#6_Advancedfunctions"> <title>Batteries user guide : Batteries.Random</title> </head> <body> <div class="navbar"><a class="pre" href="Batteries.Queue.html" title="Batteries.Queue">Previous</a> <a class="up" href="Batteries.html" title="Batteries">Up</a> <a class="post" href="Batteries.Scanf.html" title="Batteries.Scanf">Next</a> </div> <h1>Module <a href="type_Batteries.Random.html">Batteries.Random</a></h1> <pre><span class="keyword">module</span> Random: <code class="type">BatRandom</code></pre><hr width="100%"> <br> <h6 id="6_Basicfunctions">Basic functions</h6><br> <pre><span id="VALinit"><span class="keyword">val</span> init</span> : <code class="type">int -> unit</code></pre><div class="info "> Initialize the generator, using the argument as a seed. The same seed will always yield the same sequence of numbers.<br> </div> <pre><span id="VALfull_init"><span class="keyword">val</span> full_init</span> : <code class="type">int array -> unit</code></pre><div class="info "> Same as <code class="code"><span class="constructor">Random</span>.init</code> but takes more data as seed.<br> </div> <pre><span id="VALself_init"><span class="keyword">val</span> self_init</span> : <code class="type">unit -> unit</code></pre><div class="info "> Initialize the generator with a more-or-less random seed chosen in a system-dependent way.<br> </div> <pre><span id="VALbits"><span class="keyword">val</span> bits</span> : <code class="type">unit -> int</code></pre><div class="info "> Return 30 random bits in a nonnegative integer.<br> </div> <pre><span id="VALint"><span class="keyword">val</span> int</span> : <code class="type">int -> int</code></pre><div class="info "> <code class="code"><span class="constructor">Random</span>.int bound</code> returns a random integer between 0 (inclusive) and <code class="code">bound</code> (exclusive). <code class="code">bound</code> must be greater than 0 and less than 2<sup class="superscript">30</sup>.<br> </div> <pre><span id="VALint32"><span class="keyword">val</span> int32</span> : <code class="type">Int32.t -> Int32.t</code></pre><div class="info "> <code class="code"><span class="constructor">Random</span>.int32 bound</code> returns a random integer between 0 (inclusive) and <code class="code">bound</code> (exclusive). <code class="code">bound</code> must be greater than 0.<br> </div> <pre><span id="VALnativeint"><span class="keyword">val</span> nativeint</span> : <code class="type">Nativeint.t -> Nativeint.t</code></pre><div class="info "> <code class="code"><span class="constructor">Random</span>.nativeint bound</code> returns a random integer between 0 (inclusive) and <code class="code">bound</code> (exclusive). <code class="code">bound</code> must be greater than 0.<br> </div> <pre><span id="VALint64"><span class="keyword">val</span> int64</span> : <code class="type">Int64.t -> Int64.t</code></pre><div class="info "> <code class="code"><span class="constructor">Random</span>.int64 bound</code> returns a random integer between 0 (inclusive) and <code class="code">bound</code> (exclusive). <code class="code">bound</code> must be greater than 0.<br> </div> <pre><span id="VALfloat"><span class="keyword">val</span> float</span> : <code class="type">float -> float</code></pre><div class="info "> <code class="code"><span class="constructor">Random</span>.float bound</code> returns a random floating-point number between 0 (inclusive) and <code class="code">bound</code> (exclusive). If <code class="code">bound</code> is negative, the result is negative or zero. If <code class="code">bound</code> is 0, the result is 0.<br> </div> <pre><span id="VALbool"><span class="keyword">val</span> bool</span> : <code class="type">unit -> bool</code></pre><div class="info "> <code class="code"><span class="constructor">Random</span>.bool ()</code> returns <code class="code"><span class="keyword">true</span></code> or <code class="code"><span class="keyword">false</span></code> with probability 0.5 each.<br> </div> <pre><span id="VALchar"><span class="keyword">val</span> char</span> : <code class="type">unit -> char</code></pre><div class="info "> Return a random Latin-1 character.<br> </div> <pre><span id="VALfull_range_int"><span class="keyword">val</span> full_range_int</span> : <code class="type">unit -> int</code></pre><div class="info "> <code class="code">full_range_int ()</code> returns the maximum entropy possible in a single int: 31 bits on 32-bit platforms and 63 bits on 64-bit platforms. Intentionally gives different results on different platforms, so is not portable.<br> </div> <br> <h6 id="6_Enumerationsofrandomvalues">Enumerations of random values.</h6><br> <pre><span id="VALenum_bits"><span class="keyword">val</span> enum_bits</span> : <code class="type">unit -> int <a href="BatEnum.html#TYPEt">BatEnum.t</a></code></pre> <pre><span id="VALenum_int"><span class="keyword">val</span> enum_int</span> : <code class="type">int -> int <a href="BatEnum.html#TYPEt">BatEnum.t</a></code></pre> <pre><span id="VALenum_bool"><span class="keyword">val</span> enum_bool</span> : <code class="type">unit -> bool <a href="BatEnum.html#TYPEt">BatEnum.t</a></code></pre> <pre><span id="VALenum_float"><span class="keyword">val</span> enum_float</span> : <code class="type">float -> float <a href="BatEnum.html#TYPEt">BatEnum.t</a></code></pre> <pre><span id="VALenum_int32"><span class="keyword">val</span> enum_int32</span> : <code class="type">Int32.t -> Int32.t <a href="BatEnum.html#TYPEt">BatEnum.t</a></code></pre> <pre><span id="VALenum_int64"><span class="keyword">val</span> enum_int64</span> : <code class="type">Int64.t -> Int64.t <a href="BatEnum.html#TYPEt">BatEnum.t</a></code></pre> <pre><span id="VALenum_nativeint"><span class="keyword">val</span> enum_nativeint</span> : <code class="type">Nativeint.t -> Nativeint.t <a href="BatEnum.html#TYPEt">BatEnum.t</a></code></pre> <pre><span id="VALenum_char"><span class="keyword">val</span> enum_char</span> : <code class="type">unit -> char <a href="BatEnum.html#TYPEt">BatEnum.t</a></code></pre><br> <h6 id="6_Workingwithdatastructures">Working with data structures.</h6><br> <pre><span id="VALchoice"><span class="keyword">val</span> choice</span> : <code class="type">'a <a href="BatEnum.html#TYPEt">BatEnum.t</a> -> 'a</code></pre><div class="info "> <code class="code">choice e</code> returns a randomly-chosen element of <code class="code">e</code>. <p> This function only works on finite enumerations with less than 2<sup class="superscript">30</sup> elements.<br> </div> <pre><span id="VALmulti_choice"><span class="keyword">val</span> multi_choice</span> : <code class="type">int -> 'a <a href="BatEnum.html#TYPEt">BatEnum.t</a> -> 'a <a href="BatEnum.html#TYPEt">BatEnum.t</a></code></pre><div class="info "> <code class="code">multi_choice n e</code> returns an enumeration of <code class="code">n</code> randomly-chosen elements of <code class="code">e</code>.<br> </div> <pre><span id="VALshuffle"><span class="keyword">val</span> shuffle</span> : <code class="type">'a <a href="BatEnum.html#TYPEt">BatEnum.t</a> -> 'a array</code></pre><div class="info "> <code class="code">shuffle e</code> returns a new array, containing the same set of elements as <code class="code">e</code>, but in a random order. <p> Shuffling is implemented using the Fisher-Yates algorithm and works in O(n), where n is the number of elements of <code class="code">e</code>. <p> This function only works on finite enumerations with less than 2<sup class="superscript">30</sup> elements.<br> </div> <br> <h6 id="6_Advancedfunctions">Advanced functions</h6><br> <pre><span class="keyword">module</span> <a href="BatRandom.State.html">State</a>: <code class="code"><span class="keyword">sig</span></code> <a href="BatRandom.State.html">..</a> <code class="code"><span class="keyword">end</span></code></pre><div class="info"> Manipulate the current state of the random generator. </div> <pre><span id="VALget_state"><span class="keyword">val</span> get_state</span> : <code class="type">unit -> <a href="BatRandom.State.html#TYPEt">State.t</a></code></pre><div class="info "> Return the current state of the generator used by the basic functions.<br> </div> <pre><span id="VALset_state"><span class="keyword">val</span> set_state</span> : <code class="type"><a href="BatRandom.State.html#TYPEt">State.t</a> -> unit</code></pre><div class="info "> Set the state of the generator used by the basic functions.<br> </div> <pre><span class="keyword">module</span> <a href="BatRandom.Incubator.html">Incubator</a>: <code class="code"><span class="keyword">sig</span></code> <a href="BatRandom.Incubator.html">..</a> <code class="code"><span class="keyword">end</span></code></pre></body></html>