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

📄 nr02doc.htm

📁 随机数发生器C++写的
💻 HTM
📖 第 1 页 / 共 4 页
字号:
<html><head><meta http-equiv="Content-Language" content="en-nz"><meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252"><meta NAME="GENERATOR" CONTENT="Microsoft FrontPage 6.0"><meta name="ProgId" content="FrontPage.Editor.Document"><title>Newran - random number generator library</title><link rel="stylesheet" type="text/css" href="rbd.css"><link REL="SHORTCUT ICON" HREF="favicon.ico"></head><body><h1><a NAME="top"></a>Newran02C - a random number generator library</h1><p>23 April, 2006</p><p>Copyright (C) 1989, 1995, 1998, 2002: R B Davies </p><ul>  <li><a HREF="#overview">Overview</a></li>  <li><a HREF="#starting">Getting started</a></li>  <li><a HREF="#description">Descriptions of the classes to be accessed by the user</a></li>  <li><a HREF="#supporting">Descriptions of the supporting classes</a></li>  <li><a HREF="#generating">Generating numbers from other distributions</a></li>  <li><a HREF="#other">Other people's code</a></li>  <li><a HREF="#files">Files included in this package</a></li>  <li><a HREF="#class">Class structure</a></li>  <li><a HREF="#todo">To do</a></li>  <li><a href="#history">History</a></li>  <li><a HREF="ol_doc.htm">To online documentation page</a></li></ul><p>This is a C++ library for generating sequences of random numbers from a wide variety ofdistributions. It is particularly appropriate for the situation where one requiressequences of identically distributed random numbers since the set up time for each type ofdistribution is relatively long but it is efficient when generating each new randomnumber. The library includes <i>classes</i> for generating random numbers from a number ofdistributions and is easily extended to be able to generate random numbers from almost anyof the standard distributions. </p><p>Comments and bug reports to robert<b> at </b>statsresearch.co.nz [replace <b>at</b> by you-know-what].</p><p>For updates and notes see <a href="http://www.robertnz.net">http://www.robertnz.net</a>.</p><P>There are no restrictions on the use of <I>newran</I> except that I take noliability for any problems that may arise from its use.</P><P>I welcome its distribution as part of low cost CD-ROM collections. </P><P>You can use it in your commercial projects. However, if you distribute thesource, please make it clear which parts are mine and that they are availableessentially for free over the Internet. </P><p>&nbsp;</p><h2><a NAME="overview"></a>Overview</h2><p>The following are the classes for generating random numbers from particulardistributions&nbsp; </p><table BORDER="0" width="100%">  <tr>    <td VALIGN="TOP" width="20%"><a HREF="#uniform">Uniform</a></td>    <td VALIGN="TOP" width="80%">uniform distribution</td>  </tr>  <tr>    <td VALIGN="TOP" width="20%"><a HREF="#constant">Constant</a></td>    <td VALIGN="TOP" width="80%">return a constant</td>  </tr>  <tr>    <td VALIGN="TOP" width="20%"><a HREF="#exponential">Exponential</a></td>    <td VALIGN="TOP" width="80%">negative exponential distribution</td>  </tr>  <tr>    <td VALIGN="TOP" width="20%"><a HREF="#cauchy">Cauchy</a></td>    <td VALIGN="TOP" width="80%">Cauchy distribution</td>  </tr>  <tr>    <td VALIGN="TOP" width="20%"><a HREF="#normal">Normal</a></td>    <td VALIGN="TOP" width="80%">normal distribution</td>  </tr>  <tr>    <td VALIGN="TOP" width="20%"><a HREF="#chisq">ChiSq</a></td>    <td VALIGN="TOP" width="80%">non-central chi-squared distribution</td>  </tr>  <tr>    <td VALIGN="TOP" width="20%"><a HREF="#gamma">Gamma</a></td>    <td VALIGN="TOP" width="80%">gamma distribution</td>  </tr>  <tr>    <td VALIGN="TOP" width="20%"><a HREF="#pareto">Pareto</a></td>    <td VALIGN="TOP" width="80%">Pareto distribution</td>  </tr>  <tr>    <td VALIGN="TOP" width="20%"><a HREF="#poisson">Poisson</a></td>    <td VALIGN="TOP" width="80%">Poisson distribution</td>  </tr>  <tr>    <td width="20%"><a HREF="#binomial">Binomial</a></td>    <td width="80%">binomial distribution</td>  </tr>  <tr>    <td width="20%"><a HREF="#negativebinomial">NegativeBinomial</a></td>    <td width="80%">negative binomial distribution</td>  </tr></table><p>The following classes are available to the user for generating numbers from otherdistributions &nbsp; </p><table BORDER="0" WIDTH="100%">  <tr>    <td VALIGN="top" width="20%"><a HREF="#posgenx">PosGenX</a></td>    <td VALIGN="top" width="80%">Positive random numbers with a decreasing density</td>  </tr>  <tr>    <td VALIGN="top" width="20%"><a HREF="#symgenx">SymGenX</a></td>    <td VALIGN="top" width="80%">Random numbers from a symmetric unimodal density</td>  </tr>  <tr>    <td VALIGN="top" width="20%"><a HREF="#asymgenx">AsymGenX</a></td>    <td VALIGN="top" width="80%">Random numbers from an asymmetric unimodal density</td>  </tr>  <tr>    <td VALIGN="top" width="20%"><a HREF="#posgen">PosGen</a></td>    <td VALIGN="top" width="80%">Positive random numbers with a decreasing density</td>  </tr>  <tr>    <td VALIGN="top" width="20%"><a HREF="#symgen">SymGen</a></td>    <td VALIGN="top" width="80%">Random numbers from a symmetric unimodal density</td>  </tr>  <tr>    <td VALIGN="top" width="20%"><a HREF="#asymgen">AsymGen</a></td>    <td VALIGN="top" width="80%">Random numbers from an asymmetric unimodal density</td>  </tr>  <tr>    <td VALIGN="top" width="20%"><a HREF="#discretegen">DiscreteGen</a></td>    <td VALIGN="top" width="80%">Random numbers from a discrete distribution</td>  </tr>  <tr>    <td VALIGN="top" width="20%"><a HREF="#sum">SumRandom</a></td>    <td VALIGN="top" width="80%">Sum and/or product of random numbers</td>  </tr>  <tr>    <td VALIGN="top" width="20%"><a HREF="#mixed">MixedRandom</a></td>    <td VALIGN="top" width="80%">Mixture of random numbers</td>  </tr></table><p>Each of these classes has the following member functions &nbsp; </p><table BORDER="0" WIDTH="75%">  <tr>    <td VALIGN="TOP"><tt>Real Next()</tt></td>    <td VALIGN="TOP">Get a new random number</td>  </tr>  <tr>    <td VALIGN="TOP"><tt>char* Name()</tt></td>    <td VALIGN="TOP">Name of the distribution</td>  </tr>  <tr>    <td VALIGN="TOP"><tt>ExtReal Mean()</tt></td>    <td VALIGN="TOP">Mean of the distribution</td>  </tr>  <tr>    <td VALIGN="TOP"><tt>ExtReal Variance()</tt></td>    <td VALIGN="TOP">Variance of the distribution</td>  </tr></table><p>These 4 functions are declared <i>virtual</i> so it is easy to write simulationprograms that can be run with different distributions. </p><p><i>Real</i> is typedefed to be either <i>float</i> or <i>double</i>. See <aHREF="#customising">customising</a>. Note that <tt>Next()</tt> always returns a <i>Real</i>even for discrete distributions. </p><p><a HREF="#extreal">ExtReal</a> is a class which is, in effect either a <i>Real</i> orone of the following: <i>PlusInfinity</i>, <i>MinusInfinity</i>, <i>Indefinite</i> or <i>Missing</i>.I use <i>ExtReal</i> so that I can return infinite or indefinite values for the mean orvariance of a distribution. </p><p>There are two static functions in the class <i>Random</i>. </p><pre>   void Random::Set(double)</pre><p>must be called with an argument between 0 and 1 to set up the base random numbergenerator before <tt>Next()</tt> is called in any class. </p><pre>   double Random::Get()</pre><p>returns the current value of the seed. </p><p>There are two classes for doing combinations and permutations. <br>&nbsp;</p><table BORDER="0" WIDTH="100%">  <tr>    <td width="25%"><a HREF="#permutation">RandomPermutation</a></td>    <td width="75%">Draw numbers without replacement</td>  </tr>  <tr>    <td width="25%"><a HREF="#combination">RandomCombination</a></td>    <td width="75%">Draw numbers without replacement and sort</td>  </tr></table><p>There are three classes for&nbsp;generating random numbers where we want to vary the parameters at each call. It would be inefficient to use the previous classes since you would need to set up a random number object at each call.</p><table BORDER="0" WIDTH="100%">  <tr>    <td VALIGN="top" width="20%"><a href="#VariPoisson">VariPoisson</a></td>    <td VALIGN="top" width="80%">Poisson distribution</td>  </tr>  <tr>    <td VALIGN="top" width="20%"><a href="#VariBinomial">VariBinomial</a></td>    <td VALIGN="top" width="80%">Binomial distribution</td>  </tr>  <tr>    <td VALIGN="top" width="20%"><a href="#VariLogNormal">VariLogNormal</a></td>    <td VALIGN="top" width="80%">Log normal distribution</td>  </tr></table><p>Further details of all these classes including the constructors are given <aHREF="#description">below</a>. </p><h2><a NAME="starting"></a>Getting started</h2><h3><a NAME="customising"></a>Customising</h3><p>The file include.h sets a variety of options including several compiler dependentoptions. You may need to edit include.h to get the options you require. If you are using acompiler different from one I have worked with you may have to set up a new section ininclude.h appropriate for your compiler. </p><p>Borland,  Gnu, Microsoft and Watcom are recognised automatically. If none ofthese are recognised a default set of options is used. These are fine for AT&amp;T, HPUXand Sun C++. If you using a compiler I don't know about, you may have to write a new setof options. </p><p>There is an option in include.h for selecting whether you use compiler supportedexceptions, simulated exceptions, or disable exceptions. Use the option for compilersupported exceptions if and only if you have set the option on your compiler to recogniseexceptions. Disabling exceptions sometimes helps with compilers that are incompatible withmy exception simulation scheme.&nbsp; </p><table BORDER="1" WIDTH="100%">  <tr>    <td ALIGN="CENTER" WIDTH="100%">This version of <i>newran</i> does <i>not</i> do memory    clean-up with the <i>simulated</i> exceptions.</td>  </tr></table><p>If your (very old) compiler does not recognises <i>bool</i> deactivate thestatement <tt>#define bool_LIB</tt>. This will activate my Boolean class.</p><p>Activate the appropriate statement to make the element type <i>Real</i> to mean <i>float</i>or <i>double</i>. </p><p>Activate the <i>namespace</i> option if your want to use namespaces and have a compilerthat <i>really</i> does support them. </p><h3>Compiling</h3><p>You will need to compile newran.cpp, myexcept.cpp and extreal.cpp and link theresulting object files to your programs. Your source files which access <i>newran</i> willneed to have newran.h as an include file. </p><h3>Compilers</h3><p>I have tested newran02 with the following compilers (all PC ones in 32 bit consolemode)</p><table border="0" width="75%">  <tr>    <td width="50%" valign="top">Borland 5.0, 5.5, 5.6</td>    <td width="50%" valign="top">OK</td>

⌨️ 快捷键说明

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