>  Docs Center  >  IDL Reference  >  Advanced Math and Stats  >  IMSL_RAND_FROM_DATA



The IMSL_RAND_FROM_DATA function generates pseudorandom numbers from a multivariate distribution determined from a given sample.

This routine requires an IDL Advanced Math and Stats license. For more information, contact your sales or technical support representative.

Given a sample of size nsamp of observations of a k-variate random variable, IMSL_RAND_FROM_DATA generates a pseudorandom sample with approximately the same moments as the given sample. The sample obtained is the same as if sampling from a Gaussian kernel estimate of the sample density. (See Thompson 1989.) Routine IMSL_RAND_FROM_DATA uses methods described by Taylor and Thompson (1986).

Assume that the (vector-valued) observations xi are in the rows of x. An observation, xj, is chosen randomly; its nearest m (= nn) neighbors:

are determined; and the mean:


of those nearest neighbors is calculated. Next, a random sample u1, u2, ..., um is

generated from a uniform distribution with lower bound:

and upper bound:

The random variate delivered is:

The process is then repeated until n such simulated variates are generated and stored in the rows of the result.


For additional information on using XYZ Routine, see Additional Examples.

In this example, IMSL_RAND_FROM_DATA is used to generate 5 pseudorandom vectors of length 4 using the initial and final systolic pressure and the initial and final diastolic pressure from Data Set A in Afifi and Azen (1979) as the fixed sample from the population to be modeled. (Values of these four variables are in the seventh, tenth, twenty-first, and twenty-fourth columns of data set number nine in routine IMSL_STATDATA.)

IMSL_RANDOMOPT, Set = 123457
x = FLTARR(113, 4)
x(*, 0) = r(*,6)
x(*, 1) = r(*,9)
x(*, 2) = r(*,20)
x(*, 3) = r(*,23)
r = IMSL_RAND_FROM_DATA(5, x, 5)
PM, r
162.767 90.5057 153.717 104.877
153.353 78.3180 176.664 85.2155
93.6958 48.1675 153.549 71.3688
101.751 54.1855 113.121 56.2916
91.7403 58.7684 48.4368 28.0994


Result = IMSL_RAND_FROM_DATA(N_random, X, Nn [, /DOUBLE])

Return Value

N x ndim matrix containing the random multivariate vectors in its rows.



Number of random multivariate vectors to generate.


Number of nearest neighbors of the randomly selected point in x that are used to form the output point in the result.


Two dimensional array of size nsamp by ndim containing the given sample.


DOUBLE (optional)

If present and nonzero, double precision is used.

Version History



See Also

IMSL_RANDOM, IMSL_STATDATA, Overview of Random Number Generation

© 2019 Harris Geospatial Solutions, Inc. |  Legal
My Account    |    Store    |    Contact Us