1 10 package org.jgap.impl; 11 12 import org.jgap.*; 13 14 22 public class RandomGeneratorForTest 23 implements RandomGenerator, java.io.Serializable { 24 25 26 private static final String CVS_REVISION = "$Revision: 1.14 $"; 27 28 private long m_nextLong; 29 private double m_nextDouble; 30 private boolean m_nextBoolean; 31 private int[] m_nextIntSequence; 32 private float[] m_nextFloatSequence; 33 private double m_nextGaussian; 34 private int m_intIndex, m_floatIndex; 35 36 public RandomGeneratorForTest() { 37 } 38 39 public RandomGeneratorForTest(int a_nextInt) { 40 this(); 41 setNextInt(a_nextInt); 42 } 43 44 public RandomGeneratorForTest(double a_nextDouble) { 45 this(); 46 setNextDouble(a_nextDouble); 47 } 48 49 public RandomGeneratorForTest(float a_nextFloat) { 50 this(); 51 setNextFloat(a_nextFloat); 52 } 53 54 public RandomGeneratorForTest(long a_nextLong) { 55 this(); 56 setNextLong(a_nextLong); 57 } 58 59 public RandomGeneratorForTest(boolean a_nextBoolean) { 60 this(); 61 setNextBoolean(a_nextBoolean); 62 setNextInt(1); 63 } 64 65 public int nextInt() { 66 int result = m_nextIntSequence[m_intIndex++]; 67 if (m_intIndex >= m_nextIntSequence.length) { 68 m_intIndex = 0; 69 } 70 return result; 71 } 72 73 public int nextInt(int a_ceiling) { 74 return nextInt() % a_ceiling; 75 } 76 77 public long nextLong() { 78 return m_nextLong; 79 } 80 81 public double nextDouble() { 82 return m_nextDouble; 83 } 84 85 public double nextGaussian() { 86 return m_nextGaussian; 87 } 88 89 public float nextFloat() { 90 float result = m_nextFloatSequence[m_floatIndex++]; 91 if (m_floatIndex >= m_nextFloatSequence.length) { 92 m_floatIndex = 0; 93 } 94 return result; 95 } 96 97 public boolean nextBoolean() { 98 return m_nextBoolean; 99 } 100 101 public void setNextBoolean(boolean a_nextBoolean) { 102 m_nextBoolean = a_nextBoolean; 103 } 104 105 public void setNextDouble(double a_nextDouble) { 106 m_nextDouble = a_nextDouble % 1.0d; 107 } 108 109 public void setNextGaussian(double a_nextDouble) { 110 m_nextGaussian = a_nextDouble; 111 } 112 113 public void setNextFloat(float a_nextFloat) { 114 setNextFloatSequence(new float[] {a_nextFloat % 1.0f}); 115 } 116 117 public void setNextInt(int a_nextInt) { 118 setNextIntSequence(new int[] {a_nextInt}); 119 } 120 121 public void setNextLong(long a_nextLong) { 122 m_nextLong = a_nextLong; 123 } 124 125 public void setNextFloatSequence(float[] a_sequence) { 126 m_floatIndex = 0; 127 m_nextFloatSequence = a_sequence; 128 } 129 130 public void setNextIntSequence(int[] a_sequence) { 131 m_intIndex = 0; 132 m_nextIntSequence = a_sequence; 133 } 134 } 135 | Popular Tags |