random_beta

   more...
Generates pseudorandom numbers from a beta distribution.
Synopsis
#include <imsls.h>
float *imsls_f_random_beta(int n_random, float pin, float qin, 0)
The type double function is imsls_d_random_beta.
Required Arguments
int n_random (Input)
Number of random numbers to generate.
float pin (Input)
First beta distribution parameter. Argument pin must be positive.
float qin (Input)
Second beta distribution parameter. Argument qin must be positive.
Return Value
If no optional arguments are used, imsls_f_random_beta returns an array of length n_random containing the random standard beta deviates. To release this space, use imsls_free.
Synopsis with Optional Arguments
#include <imsls.h>
float *imsls_f_random_beta (int n_random, float pin, float qin,
IMSLS_RETURN_USER, float r[],
0)
Optional Arguments
IMSLS_RETURN_USER, float r[] (Output)
Array of length n_random containing the random standard beta deviates.
Description
Function imsls_f_random_beta generates pseudorandom numbers from a beta distribution with parameters pin and qin, both of which must be positive. With p = pin and q = qin, the probability density function is
where Γ () is the gamma function.
The algorithm used depends on the values of p and q. Except for the trivial cases of p = 1 or q = 1, in which the inverse CDF method is used, all of the methods use acceptance/rejection. If p and q are both less than 1, the method of Jöhnk (1964) is used. If either p or q is less than 1 and the other is greater than 1, the method of Atkinson (1979) is used. If both p and q are greater than 1, algorithm BB (Cheng 1978), which requires very little setup time, is used if n_random is less than 4; and algorithm B4PE of Schmeiser  and Babu (1980) is used if n_random is greater than or equal to 4. Note that for p and q both greater than 1, calling imsls_f_random_beta in a loop getting less than four variates on each call will not yield the same set of deviates as calling imsls_f_random_beta once and getting all the deviates at once because two different algorithms are used.
The values returned in r are less than 1.0 and greater than ɛ, where ɛ is the smallest positive number such that 1.0  ɛ is less than 1.0.
Function imsls_random_seed_set can be used to initialize the seed of the random number generator; function imsls_random_option can be used to select the form of the generator.
Example
In this example, imsls_f_random_beta generates five pseudorandom beta (3, 2) variates.
 
#include <imsls.h>
 
int main()
{
 
int n_random = 5;
int seed = 123457;
float pin = 3.0;
float qin = 2.0;
float *r;
 
imsls_random_seed_set (seed);
r = imsls_f_random_beta (n_random, pin, qin, 0);
imsls_f_write_matrix("Beta (3,2) random deviates", 1, n_random,
r, 0);
}
Output
 
Beta (3,2) random deviates
1 2 3 4 5
0.2814 0.9483 0.3984 0.3103 0.8296