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:    {  int[] a = new int[length];
18:       Random generator = new Random();
19:       
20:       for (int i = 0; i < a.length; i++)
21:          a[i] = generator.nextInt(n);
22:       
23:       return a;
24:    }
25: 
26:    /** 
27:       Prints all elements in an array.
28:       @param a the array to print
29:    */
30:    public static void print(int[] a)
31:    {  
32:       for (int i = 0; i < a.length; i++)
33:          System.out.print(a[i] + " ");
34:       System.out.println();
35:    }
36: }
37: