01: import java.util.Random;
02: 
03: /**
04:    This class contains utility methods for array 
05:    manipulation.
06: */  
07: public class ArrayUtil
08: { 
09:    /**
10:       Creates an array filled with random values.
11:       @param length the length of the array
12:       @param n the number of possible random values
13:       @return an array filled with length numbers between
14:       0 and n - 1
15:    */
16:    public static int[] randomIntArray(int length, int n)
17:    {  
18:       int[] a = new int[length];      
19:       for (int i = 0; i < a.length; i++)
20:          a[i] = generator.nextInt(n);
21:       
22:       return a;
23:    }
24: 
25:    /** 
26:       Prints all elements in an array.
27:       @param a the array to print
28:    */
29:    public static void print(int[] a)
30:    {  
31:       for (int e : a)
32:          System.out.print(e + " ");
33:       System.out.println();
34:    }
35: 
36:    private static Random generator = new Random();
37: }
38: