//This example demonstates the class Random //which belongs to package java.util //Random class has methods for generating random numbers. //In fact the number generated are pseudo random numbers. //For each execution, it produces different set of random numbers. //For more details on randomnumber generator, refer to the link // http://en.wikipedia.org/wiki/Random_number_generator // or the following famous book (available in central library) // Knuth, D.E.: The Art of Computer Programming, volume 2: Seminumerical // Algorithms. Addison-Wesley, Reading, MA, 3rd edition, 1997. import java.util.Random; class random_example { public static void main(String args[]) { Random rand = new Random(); //rand is now an object of class Random int value; for(int i = 0; i<15;i=i+1) { value = rand.nextInt(); //rand.nextInt returns the next random number value = Math.abs(value); value = value%1000; System.out.println(value); } } }