/* This program demonstates the usage of Date and Random classes from java.util package @author: A. T. Ozgelen */ import java.util.Date; import java.util.Random; public class UtilRandomDemo { public static void main(String[] args) { /* Date */ Date now = new Date(); System.out.println(now.toString()); // getTime() returns the milliseconds since the epoch (January, 1, 1970) long nowT = now.getTime(); System.out.println(nowT + "\n"); /* Random */ // instantiating a Random object without a fixed 'seed' Random rnd = new Random(5); System.out.println("new Random object rnd"); System.out.println(rnd.nextInt()); System.out.println(rnd.nextInt(50)); System.out.println(rnd.nextFloat() + "\n"); // instantiating a Random object without the 'seed' uses the current time as the 'seed' Random rnd2 = new Random(); System.out.println("new Random object rnd2"); System.out.println(rnd2.nextInt()); System.out.println(rnd2.nextInt(50)); System.out.println(rnd2.nextFloat()); } }