Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.encog.mathutil
Class LinearCongruentialGenerator

    java.lang.Object
      org.encog.mathutil.LinearCongruentialGenerator

    public class LinearCongruentialGenerator

extends Object

A predictable random number generator. This is useful for unit tests and benchmarks where we want random numbers, but we want them to be the same each time. This class exists on both Java and C# so it can even provide consistent random numbers over the two platforms. Random numbers are created using a LCG. http://en.wikipedia.org/wiki/Linear_congruential_generator

Field Summary
`static long` | `DEFAULT_INC` Default inc.
`static long` | `DEFAULT_MOD1` First part of default mod.
`static long` | `DEFAULT_MOD2` Second part of default mod.
`static long` | `DEFAULT_MULT` Default mult.
`static long` | `MAX_RAND` The maximum rand number that the standard GCC based LCG will generate.

Constructor Summary
`LinearCongruentialGenerator(long theSeed)` Construct the default LCG.
`LinearCongruentialGenerator(long theModulus, long theMultiplier, long theIncrement, long theSeed)` Create a LCG with the specified modulus, multiplier and increment.

Method Summary
`long` | `getIncrement()`
`long` | `getModulus()`
`long` | `getMultiplier()`
`long` | `getSeed()`
`double` | `nextDouble()`
`long` | `nextLong()`
`double` | `range(double min, double max)` Generate a random number in the specified range.
`void` | `setSeed(long theSeed)` Set the seed value.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### DEFAULT_MOD1

    public static final long DEFAULT_MOD1

  First part of default mod.

  See Also:
    Constant Field Values

### DEFAULT_MOD2

    public static final long DEFAULT_MOD2

  Second part of default mod.

  See Also:
    Constant Field Values

### DEFAULT_MULT

    public static final long DEFAULT_MULT

  Default mult.

  See Also:
    Constant Field Values

### DEFAULT_INC

    public static final long DEFAULT_INC

  Default inc.

  See Also:
    Constant Field Values

### MAX_RAND

    public static final long MAX_RAND

  The maximum rand number that the standard GCC based LCG will generate.

  See Also:
    Constant Field Values

Constructor Detail

### LinearCongruentialGenerator

    public LinearCongruentialGenerator(long theSeed)

  Construct the default LCG. You need only specify a seed.

  Parameters:
    `theSeed` - The seed to use.

### LinearCongruentialGenerator

    public LinearCongruentialGenerator(long theModulus,
                                       long theMultiplier,
                                       long theIncrement,
                                       long theSeed)

  Create a LCG with the specified modulus, multiplier and increment. Unless you REALLY KNOW WHAT YOU ARE DOING, just use the constructor that just takes a seed. It will set these values to the same as set by the GCC C compiler. Setting these values wrong can create fairly useless random numbers.

  Parameters:
    `theModulus` - The modulus for the LCG algorithm.
    `theMultiplier` - The multiplier for the LCG algorithm.
    `theIncrement` - The increment for the LCG algorithm.
    `theSeed` - The seed for the LCG algorithm. Using the same seed will give the same random number sequence each time, whether in Java or DotNet.

Method Detail

### getIncrement

    public final long getIncrement()

  Returns:
    The LCG increment.

### getModulus

    public final long getModulus()

  Returns:
    The LCG modulus.

### getMultiplier

    public final long getMultiplier()

  Returns:
    The LCG multiplier.

### getSeed

    public final long getSeed()

  Returns:
    The current seed. Set to a constant to start, thereafter the previously generated random number.

### nextDouble

    public final double nextDouble()

  Returns:
    The next random number as a double between 0 and 1.

### nextLong

    public final long nextLong()

  Returns:
    The next random number as a long between 0 and MAX_RAND.

### range

    public final double range(double min,
                              double max)

  Generate a random number in the specified range.

  Parameters:
    `min` - The minimum random number.
    `max` - The maximum random number.
  Returns:
    The generated random number.

### setSeed

    public final void setSeed(long theSeed)

  Set the seed value. Setting a seed to a specific value will always result in the same sequence of numbers, whether on Java or DotNet.

  Parameters:
    `theSeed` - The seed value.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2011. All Rights Reserved.