Example 1: Permutation

In this example, the getPermutations() method is used to produce a pseudorandom permutation of the integers from 1 to 10.


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

public class RandomSamplesEx1 {

    public static void main(String[] args) {
        int k = 10;

        RandomSamples rs = new RandomSamples();
        Random r = new Random(123457L);
        r.setMultiplier(16807);
        rs.setRandomObject(r);
        int[] idx = rs.getPermutation(k);

        PrintMatrix pm = new PrintMatrix("Random permutation of the integers "
                + "from 1 to 10");
        pm.print(idx);
    }
}

Output

Random permutation of the integers from 1 to 10
   0   
0   5  
1   9  
2   2  
3   8  
4   1  
5   6  
6   4  
7   7  
8   3  
9  10  

Link to Java source.