⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 randomgeneratorfortest.java

📁 一个开源的用java开发的遗传算法的封装好的工程
💻 JAVA
字号:
/*
 * This file is part of JGAP.
 *
 * JGAP offers a dual license model containing the LGPL as well as the MPL.
 *
 * For licencing information please see the file license.txt included with JGAP
 * or have a look at the top of class org.jgap.Chromosome which representatively
 * includes the JGAP license policy applicable for any file delivered with JGAP.
 */
package org.jgap.impl;

import org.jgap.*;

/**
 * A random generator only determined for testing purposes. With this, you can
 * specify the next value which will be returned. It is also possible to
 * specify a sequence to be produced.
 *
 * @author Klaus Meffert
 * @since 1.1
 */
public class RandomGeneratorForTest
    implements RandomGenerator, java.io.Serializable {

  /** String containing the CVS revision. Read out via reflection!*/
  private static final String CVS_REVISION = "$Revision: 1.14 $";

  private long m_nextLong;
  private double m_nextDouble;
  private boolean m_nextBoolean;
  private int[] m_nextIntSequence;
  private float[] m_nextFloatSequence;
  private double m_nextGaussian;
  private int m_intIndex, m_floatIndex;

  public RandomGeneratorForTest() {
  }

  public RandomGeneratorForTest(int a_nextInt) {
    this();
    setNextInt(a_nextInt);
  }

  public RandomGeneratorForTest(double a_nextDouble) {
    this();
    setNextDouble(a_nextDouble);
  }

  public RandomGeneratorForTest(float a_nextFloat) {
    this();
    setNextFloat(a_nextFloat);
  }

  public RandomGeneratorForTest(long a_nextLong) {
    this();
    setNextLong(a_nextLong);
  }

  public RandomGeneratorForTest(boolean a_nextBoolean) {
    this();
    setNextBoolean(a_nextBoolean);
    setNextInt(1);
  }

  public int nextInt() {
    int result = m_nextIntSequence[m_intIndex++];
    if (m_intIndex >= m_nextIntSequence.length) {
      m_intIndex = 0;
    }
    return result;
  }

  public int nextInt(int a_ceiling) {
    return nextInt() % a_ceiling;
  }

  public long nextLong() {
    return m_nextLong;
  }

  public double nextDouble() {
    return m_nextDouble;
  }

  public double nextGaussian() {
    return m_nextGaussian;
  }

  public float nextFloat() {
    float result = m_nextFloatSequence[m_floatIndex++];
    if (m_floatIndex >= m_nextFloatSequence.length) {
      m_floatIndex = 0;
    }
    return result;
  }

  public boolean nextBoolean() {
    return m_nextBoolean;
  }

  public void setNextBoolean(boolean a_nextBoolean) {
    m_nextBoolean = a_nextBoolean;
  }

  public void setNextDouble(double a_nextDouble) {
    m_nextDouble = a_nextDouble % 1.0d;
  }

  public void setNextGaussian(double a_nextDouble) {
    m_nextGaussian = a_nextDouble;
  }

  public void setNextFloat(float a_nextFloat) {
    setNextFloatSequence(new float[] {a_nextFloat % 1.0f});
  }

  public void setNextInt(int a_nextInt) {
    setNextIntSequence(new int[] {a_nextInt});
  }

  public void setNextLong(long a_nextLong) {
    m_nextLong = a_nextLong;
  }

  public void setNextFloatSequence(float[] a_sequence) {
    m_floatIndex = 0;
    m_nextFloatSequence = a_sequence;
  }

  public void setNextIntSequence(int[] a_sequence) {
    m_intIndex = 0;
    m_nextIntSequence = a_sequence;
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -