Chapter 12: Random Number Generation

random_uniform_discrete

Generates pseudorandom numbers from a discrete uniform distribution.

Synopsis

#include <imsls.h>

int *imsls_f_random_uniform_discrete (int n_random, int k, ..., 0)

The type double function is imsls_d_random_uniform_discrete.

Required Arguments

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

int k   (Input)
Parameter of the discrete uniform distribution. The integers 1, 2, ..., k occur with equal probability. Parameter k must be positive.

Return Value

An integer array of length n_random containing the random discrete uniform deviates.

Synopsis with Optional Arguments

#include <imsls.h>

int *imsls_f_random_uniform_discrete (int n_random, int k,
IMSLS_RETURN_USER, int ir[],
0)

Optional Arguments

IMSLS_RETURN_USER, int ir[]   (Output)
User-supplied integer array of length n_random containing the random discrete uni­form deviates.

Description

Function imsls_f_random_uniform_discrete generates pseudorandom numbers from a uniform discrete distribution over the integers 1, 2, ...k. A random integer is generated by multiplying k by a uniform (0, 1) random number, adding 1.0, and truncating the result to an integer. This, of course, is equivalent to sampling with replacement from a finite population of size k.

Example

In this example, imsls_f_random_uniform_discrete generates five pseudorandom discrete uniform deviates from a discrete uniform distribution over the integers 1 to 6.

#include <stdio.h>

#include <imsls.h>

 

int main()

{

    int n_random = 5;

    int k = 6;

    int *ir;

 

    imsls_random_seed_set(123457);

    ir = imsls_f_random_uniform_discrete(n_random, k, 0);

    imsls_i_write_matrix("Discrete uniform (1, 6) random deviates:" ,

        1, n_random, ir, IMSLS_NO_COL_LABELS, 0);

 

}

Output

Discrete uniform (1, 6) random deviates:

            6   2   5   4   6

 


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