For example,
import java.util.Random; class RandomTest { public static void main(String[] as) { Random randomSource = new Random(); if (as.length == 0) as = new String[] { "alpha", "beta", "gamma" }; final int trials = 100; for (int i = 0; i < trials; i ++) { // choose a random integer between 0 and as.length - 1 (inclusive)... final int j = randomSource.nextInt(as.length); // print a randomly selected element of as... System.out.println(as[j]); } } }
Please see the Working with Graphics lesson in sun's java tutorial.
Please see the Performing Animation section of the Working with Graphics lesson in sun's java tutorial.