Language Reference


RANDFUN Function

RANDFUN (N, "Distribution" <, param1> <, param2> <, param3>);

The RANDFUN function is part of the IMLMLIB library . The RANDFUN function is a convenient interface to the RANDGEN subroutine. If N is a positive integer, the function returns an N$\times 1$ column vector of random numbers that are drawn from the Distribution family with the specified parameters. If N is a vector that contains a pair of integers, the function returns an N[1]$\times $N[2] matrix of random numbers.

For simulation studies that generate matrices of random numbers within a DO loop, it is more efficient to use the RANDGEN subroutine.

The following example simulates data from three distributions:

  • the Bernoulli distribution with probability $p=1/2$

  • the uniform distribution on the interval $(0,1)$

  • the normal distribution with mean 5 and standard deviation 2

call randseed(123);
b = randfun({4 2}, "Bernoulli", 0.5); /* 4 rows, 2 cols */
u = randfun(4, "Uniform");
x = randfun(4, "Normal", 5, 2);
print b u x;

Figure 25.302: Random Samples from Three Distributions

b   u x
0 1 0.056701 4.956251
1 1 0.0798305 5.8587927
1 1 0.9233735 5.9284455
1 1 0.2258509 6.2806841