2.1.24.8.5 disrnd
Description
Generates an array of random integers from a general discrete distribution, seeds and generator number passed explicitly
Syntax
int disrnd( long * v, uint n, const double * vP, const uint nSizeP, int iLowerIndex, bool bIsCdf )
Parameters
- v
- [output] Pointer to a double array, which contain the results
- n
- [input] The number of pseudo-random numbers to be generated. n>=1
- vP
- [input] The PDF or CDF of the distribution
- nSizeP
- [input] The number of values supplied in p defining the PDF or CDF of the discrete distribution
- iLowerIndex
- [input] The value of the variate, assumed to be a whole number, to which the probability in vP[0] corresponds
- bIsCdf
- [input] The bool value to indicate whether vP is the PDF or CDF of the distribution
Return
Return NE_NOERROR(0) on success, otherwise error.
Examples
EX1
//This example is to generate pseudo-random numbers from a general discrete distribution
int disrnd_ex1()
{
int n = 20;
long v[20];
int iLowerIndex = -5;
bool bIsCdf = false;
double pP[11] = { 0.01, 0.02, 0.04, 0.08, 0.2, 0.3, 0.2, 0.08, 0.04, 0.02, 0.01 };
uint nSizeP = 11;
int nRet = disrnd( v, n, pP, nSizeP, iLowerIndex, bIsCdf);
if(0 != nRet)
return 0;
for(int i=0;i<n;i++)
printf("v[%d]: %d\n",i, v[i]);
return 1;
}
Remark
See Also
binornd
Header to Include
origin.h
Reference
|