Generates pseudorandom numbers from a discrete uniform distribution.
#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.
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.
An integer array of length n_random containing the random discrete uniform deviates.
#include <imsls.h>
int
*imsls_f_random_uniform_discrete (int n_random,
int k,
IMSLS_RETURN_USER,
int ir[],
0)
IMSLS_RETURN_USER, int ir[]
(Output)
User-supplied integer array of length n_random containing
the random discrete uniform deviates.
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.
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);
}
Discrete uniform (1, 6) random deviates:
6 2 5 4 6