random_uniform
Generates pseudorandom numbers from a uniform (0,1) distribution.
Synopsis
#include <imsl.h>
float *imsl_f_random_uniform (int n_random, , 0)
The type double function is imsl_d_random_uniform.
Required Arguments
int n_random (Input)
Number of random numbers to generate.
Return Value
A pointer to a vector of length n_random containing the random uniform (0, 1) deviates.
Synopsis with Optional Arguments
#include <imsl.h>
float *imsl_f_random_uniform (int n_random,
IMSL_RETURN_USER, float r[],
0)
Optional Arguments
IMSL_RETURN_USER, float r[] (Output)
If specified, the array of length n_random containing the random uniform (0, 1) deviates is returned in the user-provided array r.
Description
The function imsl_f_random_uniform generates pseudorandom numbers from a uniform (0, 1) distribution using a multiplicative congruential method. The form of the generator is
xi  cxi-1 mod (231  1)
Each xi is then scaled into the unit interval (0,1). The possible values for c in the generators are 16807, 397204094, and 950706376. The selection is made by the function imsl_random_option. The choice of 16807 will result in the fastest execution time. If no selection is made explicitly, the functions use the multiplier 16807.
The function imsl_random_seed_set can be used to initialize the seed of the random number generator. The function imsl_random_option can be used to select the form of the generator.
The user can select a shuffled version of these generators. In this scheme, a table is filled with the first 128 uniform (0, 1) numbers resulting from the simple multiplicative congruential generator. Then, for each xi from the simple generator, the low-order bits of xi are used to select a random integer, j, from 1 to 128. The j-th entry in the table is then delivered as the random number; and xi, after being scaled into the unit interval, is inserted into the j-th position in the table.
The values returned by imsl_f_random_uniform are positive and less than 1.0. Some values returned may be smaller than the smallest relative spacing, however. Hence, it may be the case that some value, for example r[i], is such that 1.0  r[i] = 1.0.
Deviates from the distribution with uniform density over the interval (a, b) can be obtained by scaling the output from imsl_f_random_uniform. The following statements (in single precision) would yield random deviates from a uniform (ab) distribution.
 
float *r;
r =imsl_f_random_uniform (n_random, 0);
for (i=0; i<n_random; i++) r[i]*(b-a) +a;
Example
In this example, imsl_f_random_uniform is used to generate five pseudorandom uniform numbers. Since imsl_random_option is not called, the generator used is a simple multiplicative congruential one with a multiplier of 16807.
 
#include <imsl.h>
#include <stdio.h>
 
#define N_RANDOM 5
 
int main()
{
float *r;
 
imsl_random_seed_set(123457);
 
r = imsl_f_random_uniform(N_RANDOM, 0);
 
printf("Uniform random deviates: %8.4f%8.4f%8.4f%8.4f%8.4f\n",
r[0], r[1], r[2], r[3], r[4]);
}
Output
 
Uniform random deviates: 0.9662 0.2607 0.7663 0.5693 0.8448