Generates pseudorandom numbers from a triangular distribution on the interval (0, 1).
#include <imsls.h>
float *imsls_f_random_triangular (int n_random, ..., 0)
The type double function is imsls_d_random_triangular.
int n_random
(Input)
Number of random numbers to generate.
An array of length n_random containing the random deviates of a triangular distribution.
#include <imsls.h>
float
*imsls_f_random_triangular (int n_random,
IMSLS_RETURN_USER, float r[],
0)
IMSLS_RETURN_USER, float r[]
(Output)
User-supplied array of length n_random containing
the random triangular deviates.
Function imsls_f_random_triangular generates pseudorandom numbers from a triangular distribution over the unit interval. The probability density function is f (x) = 4x, for 0 ≤ x ≤ 0.5, and f (x) = 4 (1 − x), for 0.5 < x ≤ 1. An inverse CDF technique is used.
In this example, imsls_f_random_triangular is used to generate five pseudorandom deviates from a triangular distribution.
#include <stdio.h>
#include <imsls.h>
int main()
{
int n_random = 5;
float *r;
imsls_random_seed_set(123457);
r = imsls_f_random_triangular(n_random, 0);
imsls_f_write_matrix("Triangular random deviates:",
1, n_random, r, IMSLS_NO_COL_LABELS, 0);
}
Triangular random deviates:
0.8700 0.3610 0.6581 0.5360 0.7215
Visual Numerics, Inc. PHONE: 713.784.3131 FAX:713.781.9260 |