Thread: Random Integers
View Single Post
  #2 (permalink)  
Old 12-08-2007, 10:42 AM
hardwired hardwired is offline
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
Code:
import java.util.Random; public class Test { static Random seed = new Random(); public static void main(String[] args) { test(0, 20); test(5, 10); } private static void test(int low, int high) { int min = Integer.MAX_VALUE; int max = -Integer.MAX_VALUE; int range = high - low +1; for(int j = 0; j < 500; j++) { int n = low + seed.nextInt(range); if(n < min) min = n; if(n > max) max = n; } System.out.printf("min = %d max = %d%n", min, max); } }
Reply With Quote