derandom.java

来自「Differential Evolution(JAVA)」· Java 代码 · 共 62 行

JAVA
62
字号
package DeApp1.de;
import java.io.*;
import java.util.Random;   // Provides random number generators


public class DERandom extends Random
/***********************************************************
**                                                        **
** Random number generator. Certainly not the best one    **
** around. So if you are not satisfied, implement your    **
** own one.                                               **
**                                                        **
** Authors:            Mikal Keenan                       **
**                     Rainer Storn                       **
**                                                        **
***********************************************************/
{

  public DERandom ()
  /*********************************************************
  ** Constructor initializes the generator.               **
  *********************************************************/
  { 
	  setMySeed (0);
  }


  public void setMySeed (long seed)
  /*********************************************************
  ** Random initialization. Hence your optimization       **
  ** results may differ from run to run.                  **
  *********************************************************/
  { 
	if (seed == 0)
    seed = (long) System.currentTimeMillis();
    setSeed (seed);
  }


  public final int nextValue (int max) // BUG:: infinite loop if this method is called next
  /*********************************************************
  ** Fetch the next integer random number ex [0,max].     **
  *********************************************************/
  {
    return (int) (nextDouble() * (double) max);
  }


  public final double nextValue (double range) //BUG:: infinite loop if this method is called next
  /************************************************************
  ** Fetch the next double random number ex [-range,+range]. **
  ************************************************************/
  {
    return range * (1.0 - 2.0 * nextDouble());
  }
}





⌨️ 快捷键说明

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