CNL Stat : Random Number Generation : random_exponential
random_exponential
Generates pseudorandom numbers from a standard exponential distribution.
Synopsis
#include <imsls.h>
float *imsls_f_random_exponential(int n_random, 0)
The type double function is imsls_d_random_exponential.
Required Arguments
int n_random (Input)
Number of random numbers to generate.
Return Value
An array of length n_random containing the random standard exponential deviates.
Synopsis with Optional Arguments
#include <imsls.h>
float *imsls_f_random_exponential (int n_random,
IMSLS_RETURN_USER, float r[],
0)
Optional Arguments
IMSLS_RETURN_USER, float r[] (Output)
User-supplied array of length n_random containing the random standard exponential deviates.
Description
Function imsls_f_random_exponential generates pseudorandom numbers from a standard exponential distribution. The probability density function is f (x) = ex, for x > 0. Function imsls_f_random_exponential uses an antithetic inverse CDF technique; that is, a uniform random deviate U is generated, and the inverse of the exponential cumulative distribution function is evaluated at 1.0  U to yield the exponential deviate.
Deviates from the exponential distribution with mean θ can be generated by using imsls_f_random_exponential and then multiplying each entry in r by θ.
Example
In this example, imsls_f_random_exponential generates five pseudorandom deviates from a standard exponential distribution.
 
#include <imsls.h>
#include <stdio.h>
 
#define N_RANDOM 5
 
int main()
{
int seed = 123457;
int n_random = N_RANDOM;
float *r;
 
imsls_random_seed_set(seed);
 
r = imsls_f_random_exponential(n_random,
0);
 
printf("%s: %8.4f%8.4f%8.4f%8.4f%8.4f\n",
"Exponential random deviates", r[0], r[1], r[2], r[3], r[4]);
}
Output
 
Exponential random deviates: 0.0344 1.3443 0.2662 0.5633 0.1686