// // RandomRange.java // Anneal // Adds the nextInt( int n ) method // in case we're in Java <= 1.1 which doesn't have it. // // Created by sw on Sun Sep 15 2002. // Copyright (c) 2001 __MyCompanyName__. All rights reserved. // package net.tiac.home.sw.anneal; import java.util.Random; public class RandomRange extends java.util.Random { public RandomRange( ) { super(); } public RandomRange( long seed ) { super( seed ); } // This is copied straight from Sun's description of the method: public int nextInt(int n) { if (n<=0) throw new IllegalArgumentException("n must be positive"); if ((n & -n) == n) // i.e., n is a power of 2 return (int)((n * (long)next(31)) >> 31); int bits, val; do { bits = next(31); val = bits % n; } while(bits - val + (n-1) < 0); return val; } }