1  import java.util.Random;
  2  
  3  /**
  4     This class contains utility methods for array 
  5     manipulation.
  6  */  
  7  public class ArrayUtil
  8  { 
  9     /**
 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        Random generator = new Random();
 20        
 21        for (int i = 0; i < a.length; i++)
 22           a[i] = generator.nextInt(n);
 23        
 24        return a;
 25     }
 26  
 27     /** 
 28        Prints all elements in an array.
 29        @param a the array to print
 30     */
 31     public static void print(int[] a)
 32     {  
 33        for (int i = 0; i < a.length; i++)
 34           System.out.print(a[i] + " ");
 35        System.out.println();
 36     }
 37  }
 38