Chapter 12: Random Number Generation

.p>.CSCH12.DOC!RANDOM_TRIANGULAR;random_triangular

Generates pseudorandom numbers from a triangular distribution on the interval (0, 1).

Synopsis

#include <imsls.h>

float *imsls_f_random_triangular (int n_random, ..., 0)

The type double function is imsls_d_random_triangular.

Required Arguments

int n_random   (Input)
Number of random numbers to generate.

Return Value

An array of length n_random containing the random deviates of a triangular distribution.

Synopsis with Optional Arguments

#include <imsls.h>

float *imsls_f_random_triangular (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 triangular deviates.

Description

Function imsls_f_random_triangular generates pseudorandom numbers from a triangular distribu­tion 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.

Example

In this example, imsls_f_random_triangular is used to generate five pseudorandom deviates from a triangular distribution.

#include <stdio.h>

#include <imsls.h>

 

void 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);

}

Output

                Triangular random deviates:

    0.8700      0.3610      0.6581      0.5360      0.7215


Visual Numerics, Inc.
Visual Numerics - Developers of IMSL and PV-WAVE
http://www.vni.com/
PHONE: 713.784.3131
FAX:713.781.9260