⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nr02doc.htm

📁 随机数生成程序
💻 HTM
📖 第 1 页 / 共 3 页
字号:
  <li>Indefinite</li>  <li>Missing</li></ul><p>The arithmetic functions <tt>+</tt>, <tt>-</tt>, <tt>*</tt>, <tt>/</tt> are defined inthe obvious ways, as is <tt>&lt;&lt;</tt> for printing. The constructor can take either aReal or a value of <tt>EXT_REAL_CODE</tt> as an argument. If there is no argument theobject is given the value <i>Missing</i>. Member function <tt>IsReal()</tt> returns <i>true</i>if the enumeration value is <i>Finite</i> and in this case value of the Real can be foundwith <tt>Value()</tt>. The enumeration value can be found with member function <tt>Code()</tt>.</p><p><i>ExtReal</i> is used at the type for values returned from the <i>Mean</i> and <i>Variance</i>member functions since these values may be infinite, indefinite or missing. </p><p>&nbsp; </p><h2><a NAME="supporting"></a><font COLOR="#FF0000">Descriptions of the supporting classes:</font></h2><h3><font COLOR="#FF0000">ChiSq1:</font></h3><p>Non-central chi-squared with one degree of freedom. Used as part of ChiSq. </p><h3><font COLOR="#FF0000">Gamma1:</font></h3><p>This generates random numbers from a gamma distribution with shape parameter <tt>alpha&lt; 1</tt>. Because the density is infinite at <i>x</i> = 0 a power transform isrequired. The constructor takes <tt>alpha</tt> as an argument. </p><h3><font COLOR="#FF0000">Gamma2:</font></h3><p>Gamma distribution for the shape parameter, <tt>alpha</tt>, greater than 1. Theconstructor takes <tt>alpha</tt> as the argument. </p><h3><font COLOR="#FF0000">Poisson1:</font></h3><p>Poisson distribution; derived from AsymGen. The constructor takes the mean as theargument. Used by Poisson for values of the mean greater than 10. </p><h3><font COLOR="#FF0000">Poisson2:</font></h3><p>Poisson distribution with mean less than or equal to 10. Uses DiscreteGen. Constructortakes the mean as its argument. </p><h3><font COLOR="#FF0000">Binomial1:</font></h3><p>Binomial distribution; derived from AsymGen. Used by Binomial for <tt>n &gt;= 40</tt>.Constructor takes <i>n</i> and <i>p</i> as arguments. </p><h3><font COLOR="#FF0000">Binomial2:</font></h3><p>Binomial distribution with <tt>n &lt; 40</tt>. Uses DiscreteGen. Constructor takes <i>n</i>and <i>p</i> as arguments. </p><h3><font COLOR="#FF0000">AddedRandom, SubtractedRandom, MultipliedRandom, ShiftedRandom,ReverseShiftedRandom, ScaledRandom, RepeatedRandom, SelectedRandom, AddedSelectedRandom:</font></h3><p>These are used by SumRandom and MixedRandom. </p><p>&nbsp; </p><h2><a NAME="generating"></a><font COLOR="#FF0000">Generating numbers from otherdistributions:</font></h2><table BORDER="0" CELLSPACING="4" CELLPADDING="4">  <tr>    <th ALIGN="LEFT" VALIGN="TOP"><b>Distribution type</b></th>    <th ALIGN="LEFT" VALIGN="TOP"><b>Method</b></th>    <th ALIGN="LEFT" VALIGN="TOP"><b>Example</b></th>  </tr>  <tr>    <td VALIGN="TOP">Continuous finite unimodal density (no parameters, can calculate density)</td>    <td VALIGN="TOP">Use <a HREF="#posgenx">PosGenX</a>, <a HREF="#symgenx">SymGenX</a> or <a    HREF="#asymgenx">AsymGenX</a>.</td>    <td VALIGN="TOP"></td>  </tr>  <tr>    <td VALIGN="TOP">Continuous finite unimodal density (with parameters, can calculate    density)</td>    <td VALIGN="TOP">Derive a new class from <a HREF="#posgen">PosGen</a>, <a HREF="#symgen">SymGen</a>    or <a HREF="#asymgen">AsymGen</a>, over-ride <i>Density</i>.</td>    <td VALIGN="TOP">Gamma2</td>  </tr>  <tr>    <td VALIGN="TOP">Can calculate inverse of distribution</td>    <td VALIGN="TOP">Transform <a HREF="#random">uniform random</a> number.</td>    <td VALIGN="TOP">Pareto</td>  </tr>  <tr>    <td VALIGN="TOP">Transformation of supported random number</td>    <td VALIGN="TOP">Derive a new class from the existing class</td>    <td VALIGN="TOP">ChiSq1</td>  </tr>  <tr>    <td VALIGN="TOP">Transformation of several random numbers</td>    <td VALIGN="TOP">Derive new class from <a HREF="#random">Random</a>; generate the new    random number from the existing generators.</td>    <td VALIGN="TOP">ChiSq</td>  </tr>  <tr>    <td VALIGN="TOP">Density with infinite singularity</td>    <td VALIGN="TOP">Transform a random variable generated by <a HREF="#posgen">PosGen</a>, <a    HREF="#symgen">SymGen</a> or <a HREF="#asymgen">AsymGen</a>.</td>    <td VALIGN="TOP">Gamma1</td>  </tr>  <tr>    <td VALIGN="TOP">Distribution with several modes</td>    <td VALIGN="TOP">Breakdown into a <a HREF="#mixed">mixture</a> of unimodal distributions.</td>    <td VALIGN="TOP"></td>  </tr>  <tr>    <td VALIGN="TOP">Linear or quadratic combination of supported random numbers</td>    <td VALIGN="TOP">Use <a HREF="#sum">SumRandom</a>.</td>    <td VALIGN="TOP"></td>  </tr>  <tr>    <td VALIGN="TOP">Mixture of supported random numbers</td>    <td VALIGN="TOP">Use <a HREF="#mixed">MixedRandom</a>.</td>    <td VALIGN="TOP"></td>  </tr>  <tr>    <td VALIGN="TOP">Discrete distribution (&lt; 100 possible values)</td>    <td VALIGN="TOP">Use <a HREF="#discretegen">DiscreteGen</a>.</td>    <td VALIGN="TOP">Poisson2</td>  </tr>  <tr>    <td VALIGN="TOP">Discrete distribution (many possible values)</td>    <td VALIGN="TOP">Use <a HREF="#posgen">PosGen</a>, <a HREF="#symgen">SymGen</a> or <a    HREF="#asymgen">AsymGen</a>.</td>    <td VALIGN="TOP">Poisson1</td>  </tr></table><p>&nbsp; </p><h2><a NAME="other"></a><font COLOR="#FF0000">Other people's code:</font></h2><p>The gamma function and Shell sort routines are adapted from <i>Numerical Recipes in C</i>by Press, Flannery, Teukolsky, Vetterling published by the Cambridge University Press. </p><p>&nbsp; </p><h2><a NAME="files"></a><font COLOR="#FF0000">Files included in this package:</font></h2><table BORDER="0" CELLSPACING="0" CELLPADDING="0" WIDTH="100%">  <tr>    <td VALIGN="TOP">readme.txt</td>    <td VALIGN="TOP">readme file</td>  </tr>  <tr>    <td VALIGN="TOP">newran.htm</td>    <td VALIGN="TOP">this file</td>  </tr>  <tr>    <td VALIGN="TOP">newran.h</td>    <td VALIGN="TOP">header file for <i>newran</i></td>  </tr>  <tr>    <td VALIGN="TOP">newran.cpp</td>    <td VALIGN="TOP">main code file</td>  </tr>  <tr>    <td VALIGN="TOP">extreal.h</td>    <td VALIGN="TOP">header file for <i>extended reals</i></td>  </tr>  <tr>    <td VALIGN="TOP">extreal.cpp</td>    <td VALIGN="TOP">code file for <i>extended reals</i></td>  </tr>  <tr>    <td VALIGN="TOP">boolean.h</td>    <td VALIGN="TOP">definition of <i>bool</i></td>  </tr>  <tr>    <td VALIGN="TOP">include.h</td>    <td VALIGN="TOP">option file</td>  </tr>  <tr>    <td VALIGN="TOP">tryrand.cpp</td>    <td VALIGN="TOP">test file</td>  </tr>  <tr>    <td VALIGN="TOP">tryrand1.cpp</td>    <td VALIGN="TOP">called by tryrand - histograms of simple examples</td>  </tr>  <tr>    <td VALIGN="TOP">tryrand2.cpp</td>    <td VALIGN="TOP">called by tryrand - histograms of advanced examples</td>  </tr>  <tr>    <td VALIGN="TOP">tryrand3.cpp</td>    <td VALIGN="TOP">called by tryrand - statistical tests</td>  </tr>  <tr>    <td VALIGN="TOP">tryrand4.cpp</td>    <td VALIGN="TOP">called by tryrand - test permutations</td>  </tr>  <tr>    <td VALIGN="TOP">hist.cpp</td>    <td VALIGN="TOP">called by tryrand - draw histogram</td>  </tr>  <tr>    <td VALIGN="TOP">tryrand.txt</td>    <td VALIGN="TOP">output from tryrand</td>  </tr>  <tr>    <td VALIGN="TOP">nrcc.mak</td>    <td VALIGN="TOP">make file for CC compiler</td>  </tr>  <tr>    <td VALIGN="TOP">nrgnu.mak</td>    <td VALIGN="TOP">make file for gnu G++ compiler</td>  </tr>  <tr>    <td VALIGN="TOP">nrwat.mak</td>    <td VALIGN="TOP">makefile for Watcom 32 bit 10a compiler</td>  </tr></table><p>&nbsp; </p><h2><a NAME="class"></a><font COLOR="#FF0000">Class structure:</font></h2><p>The following diagram gives the class hierarchy of the package. </p><pre><font SIZE="-1"><b>ExtReal</b>.......................... <i>Extended real numbers</i><b>Random</b>........................... Uniform random number generator&nbsp;|&nbsp;+---Constant.................... Return a constant&nbsp;|&nbsp;+---PosGen...................... Used by PosGenX etc&nbsp;|&nbsp;&nbsp;&nbsp; |&nbsp;|&nbsp;&nbsp;&nbsp; +---PosGenX................ Positive random #s from decreasing density&nbsp;|&nbsp;&nbsp;&nbsp; |&nbsp;|&nbsp;&nbsp;&nbsp; +---Exponential............ Negative exponential rng&nbsp;|&nbsp;&nbsp;&nbsp; |&nbsp;|&nbsp;&nbsp;&nbsp; +---Gamma1................. Used by Gamma (shape parameter &lt; 1)&nbsp;|&nbsp;&nbsp;&nbsp; |&nbsp;|&nbsp;&nbsp;&nbsp; +---SymGen................. Used by SymGenX etc&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; +---SymGenX........... Random numbers from symmetric density&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; +---Cauchy............ Cauchy random number generator&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; +---Normal............ Standard normal random number generator&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; +---ChiSq1....... Used by ChiSq (one df)&nbsp;|&nbsp;&nbsp;+---AsymGen..................... Used by AsymGenX etc&nbsp;|&nbsp;&nbsp;&nbsp; |&nbsp;|&nbsp;&nbsp;&nbsp; +---AsymGenX............... Random numbers from asymmetric density&nbsp;|&nbsp;&nbsp;&nbsp; |&nbsp;|&nbsp;&nbsp;&nbsp; +---Poisson1............... Used by Poisson (mean &gt; 8)&nbsp;|&nbsp;&nbsp;&nbsp; |&nbsp;|&nbsp;&nbsp;&nbsp; +---Binomial1.............. Used by Binomial (n &gt;= 40)&nbsp;|&nbsp;&nbsp;&nbsp; |&nbsp;|&nbsp;&nbsp;&nbsp; +---NegativeBinomial....... Negative binomial random number generator&nbsp;|&nbsp;&nbsp;&nbsp; |&nbsp;|&nbsp;&nbsp;&nbsp; +---Gamma2................. Used by Gamma (shape parameter &gt; 1)&nbsp;|&nbsp;+---ChiSq....................... Non-central chi-squared rng&nbsp;|&nbsp;+---Gamma....................... Gamma random number generator&nbsp;|&nbsp;+---Pareto...................... Pareto random number generator&nbsp;|&nbsp;+---DiscreteGen................. Discrete random number generator&nbsp;|&nbsp;+---Poisson2.................... Used by Poisson (mean &lt;= 8)&nbsp;|&nbsp;+---Binomial2................... Used by Binomial (n &lt; 40)&nbsp;|&nbsp;+---Poisson..................... Poisson random number generator&nbsp;|&nbsp;+---Binomial.................... Binomial random number generator&nbsp;|&nbsp;+---SumRandom................... Sum of random numbers&nbsp;|&nbsp;+---MixedRandom................. Mixture of random numbers&nbsp;|&nbsp;+---MultipliedRandom............ Used by SumRandom&nbsp;|&nbsp;&nbsp;&nbsp; |&nbsp;|&nbsp;&nbsp;&nbsp; +---AddedRandom............ Used by SumRandom&nbsp;|&nbsp;&nbsp;&nbsp; |&nbsp;|&nbsp;&nbsp;&nbsp; +---SubtractedRandom....... Used by SumRandom&nbsp;|&nbsp;+---ShiftedRandom............... Used by SumRandom&nbsp;|&nbsp;&nbsp;&nbsp; |&nbsp;|&nbsp;&nbsp;&nbsp; +---ReverseShiftedRandom... Used by SumRandom&nbsp;|&nbsp;&nbsp;&nbsp; |&nbsp;|&nbsp;&nbsp;&nbsp; +---ScaledRandom........... Used by SumRandom&nbsp;|&nbsp;+---NegatedRandom.......... .... Used by SumRandom&nbsp;|&nbsp;+---RepeatedRandom.............. Used by SumRandom&nbsp;|&nbsp;+---AddedSelectedRandom......... Used by MixedRandom&nbsp;|&nbsp;+---SelectedRandom.............. Used by MixedRandom<b>RandomPermutation</b>................ Random permutation&nbsp;|&nbsp;+---RandomCombination........... Sorted random permutation</font></pre><p>&nbsp; </p><h2><a NAME="todo"></a><font COLOR="#FF0000">To do:</font></h2><ul>  <li>More modern alternatives to the <a HREF="#random">LGM generator</a>;</li>  <li>Additional generator classes;</li>  <li>Better methods for combinations and permutations with large <tt>N</tt> and small <tt>M</tt>;</li>  <li>An alternative (slower) class for Poisson with short setup time.</li></ul><p>&nbsp;</p><h2><a name="history"></a><font COLOR="#FF0000">History:</font></h2><p>August, 1998 - update exception package; work around problem with MS VC++ 5</p><p>January, 1998 - version compatible with newmat09</p><p>1995 - <em>newran</em> version, additional distributions</p><p>1989 - initial version</p><hr><p><a HREF="#top">Go to top</a> </p><p><a HREF="ol_doc.htm">To online documentation page</a>&nbsp; </p></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -