package com.imsl.test.example.stat;
import com.imsl.stat.*;
import com.imsl.math.PrintMatrix;
/**
*
* Selects a pseudorandom sample from a million records.
*
*
* In this example, the getPermutations()
and
* getSampleIndices()
methods are used to sample ten values from a
* hypothetical vector of 1,000,000 values.
*
*
* @see Code
* @see Output
*/
public class RandomSamplesEx4 {
public static void main(String[] args) {
int nsamp = 10;
int xlength = 1000000;
RandomSamples rs = new RandomSamples();
Random r = new Random(123457L);
r.setMultiplier(16807);
rs.setRandomObject(r);
int[] idx = rs.getSampleIndices(nsamp, xlength);
int[] perm = rs.getPermutation(nsamp);
int[] samp = new int[nsamp];
for (int i = 0; i < nsamp; i++) {
samp[i] = idx[perm[i] - 1];
}
PrintMatrix pm = new PrintMatrix("Random Sample");
pm.print(samp);
}
}