package geneticAnt; // Random numbers from 0 to n - 1 import java.util.*; public class IntRandom extends Random { Random r; int n; public IntRandom(int n) { try { Thread.sleep(0050); } catch (InterruptedException e) {} ; this.n = n; r = new Random(); } public IntRandom(int n, long seed) { try { Thread.sleep(0050); } catch (InterruptedException e) {} ; this.n = n; r = new Random(seed); } public int nextInt() { int x = r.nextInt(); if (x < 0) x = -x - 1; // allows 0 twice... return x % n; } public static void main(String args[]) { // Test it IntRandom r = new IntRandom(10); for (int i = 0; i < 10; i++) System.out.println( r.nextInt()); } }