Example 2: Sample Indices

In this example, the getSampleIndices() method is used to generate the indices of a pseudorandom sample of size 5 from a population of size 100.


import com.imsl.stat.*;
import com.imsl.math.PrintMatrix;

public class RandomSamplesEx2 {

    public static void main(String[] args) {
        int nSamp = 5;
        int nPop = 100;

        RandomSamples rs = new RandomSamples();
        Random r = new Random(123457L);
        r.setMultiplier(16807);
        rs.setRandomObject(r);
        int[] idx = rs.getSampleIndices(nSamp, nPop);

        PrintMatrix pm = new PrintMatrix("Random Sample");
        pm.print(idx);
    }
}

Output

Random Sample
   0   
0   2  
1  22  
2  53  
3  61  
4  79  

Link to Java source.