1 package org.jgap.util; 2 3 4 31 public class randomMCG extends randomX { 32 long state; 33 34 36 38 39 public randomMCG() { 40 this.setSeed(System.currentTimeMillis()); 41 } 42 43 48 49 public randomMCG(long seed) throws IllegalArgumentException { 50 this.setSeed(seed); 51 } 52 53 55 60 61 public void setSeed(long seed) throws IllegalArgumentException { 62 int i; 63 64 if (seed == 0) { 65 throw new IllegalArgumentException ("seed must be nonzero"); 66 } 67 super.setSeed(); state = seed & 0xFFFFFFFFL; 69 for (i = 0; i < 11; i++) { 70 nextByte(); 71 } 72 } 73 74 78 79 public byte nextByte() { 80 state = (state * 16807) & 0x7FFFFFFFL; 81 return (byte) ((state >> 11) & 0xFF); 82 } 83 }; 84 | Popular Tags |