IMSL C Stat Library
random_student_t
Generates pseudorandom numbers from a Student’s t distribution.
Synopsis
#include <imsls.h>
float *imsls_f_random_student_t(int n_random, float df, 0)
The type double function is imsls_d_random_student_t.
Required Arguments
int n_random (Input)
Number of random numbers to generate.
float df (Input)
Degrees of freedom. Parameter df must be positive.
Return Value
An array of length n_random containing the random deviates of a Student’s t distribution.
Synopsis with Optional Arguments
#include <imsls.h>
float *imsls_f_random_student_t (int n_random, float df,
IMSLS_MEAN, float mean,
IMSLS_VARIANCE, float variance,
IMSLS_RETURN_USER, float r[],
0)
Optional Arguments
IMSLS_MEAN, float mean (Input)
Mean of the Student’s t distribution.
Default: mean = 0.0
IMSLS_VARIANCE, float variance (Input)
Variance of the Student’s t distribution.
Default: variance = 1.0
IMSLS_RETURN_USER, float r[] (Output)
User-supplied array of length n_random containing the random Student’s t deviates.
Description
Function imsls_f_random_student_t generates pseudorandom numbers from a Student’s t distribution with df degrees of freedom, using a method suggested by Kinderman et al. (1977). The method (“TMX” in the reference) involves a representation of the t density as the sum of a triangular density over (2, 2) and the difference of this and the t density. The mixing probabilities depend on the degrees of freedom of the t distribution. If the triangular density is chosen, the variate is generated as the sum of two uniforms; otherwise, an acceptance/rejection method is used to generate the difference density.
Example
In this example, imsls_f_random_student_t generates five pseudorandom deviates from a Student’s t distribution with 12 degrees of freedom.
 
#include <imsls.h>
#include <stdio.h>
int main()
{
    int    seed = 123457, n_random = 5;
    float  df = 12.0, *r;
    imsls_random_seed_set (seed);
    r = imsls_f_random_student_t (n_random, df, 0);
    printf("Student's t deviates with %8.4f degrees "
        "of freedom:", df);
    printf("\n%8.4f %8.4f %8.4f %8.4f %8.4f\n",
           r[0], r[1], r[2], r[3], r[4]);
}
Output
 
Student's t deviates with 12.0000 degrees of freedom:
0.6152 1.1468 0.0877 1.3318 -0.9933