Class RandomSequence

java.lang.Object
com.softsynth.jmsl.util.RandomSequence
All Implemented Interfaces:
SequenceGenerator
Direct Known Subclasses:
RandomWalkSequence

public class RandomSequence
extends java.lang.Object
implements SequenceGenerator
Generate evenly distributed pseudo-random sequence of integers within a given inclusive range. By setting the seed, one can regenerate a prior sequence.
Author:
Phil Burk and Nick Didkovsky
  • Constructor Summary

    Constructors
    Constructor Description
    RandomSequence()  
  • Method Summary

    Modifier and Type Method Description
    int choose​(int numChoices)  
    int getMaximum()  
    int getMinimum()  
    int getNext()  
    int getSeed()  
    int next()
    Generate next value.
    void randomize()
    Set seed from system time.
    void reset()
    Reset sequence generator so that it will restart at beginning.
    void setMaximum​(int maximum)
    Set maximum value returned by next().
    If minimum is 5 and maximum is 8 then next() will return random values including 5,6,7 AND 8.
    void setMinimum​(int minimum)  
    void setNext​(int next)
    Set next value in sequence.
    void setSeed​(int seed)
    Set sequence seed.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • RandomSequence

      public RandomSequence()
  • Method Details

    • randomize

      public void randomize()
      Set seed from system time. This will result in a unique sequence each time it is called.
      Specified by:
      randomize in interface SequenceGenerator
    • choose

      public int choose​(int numChoices)
      Returns:
      random number between 0 and numChoices-1
    • next

      public int next()
      Generate next value.
      Specified by:
      next in interface SequenceGenerator
      Returns:
      next value in sequence.
    • getNext

      public int getNext()
      Specified by:
      getNext in interface SequenceGenerator
      Returns:
      next value in sequence.
    • setNext

      public void setNext​(int next)
      Set next value in sequence.
      Specified by:
      setNext in interface SequenceGenerator
    • setSeed

      public void setSeed​(int seed)
      Set sequence seed.
      Specified by:
      setSeed in interface SequenceGenerator
    • getSeed

      public int getSeed()
      Specified by:
      getSeed in interface SequenceGenerator
      Returns:
      seed set by setSeed.
    • reset

      public void reset()
      Reset sequence generator so that it will restart at beginning.
      Specified by:
      reset in interface SequenceGenerator
    • getMinimum

      public int getMinimum()
      Returns:
      minimum value returned by next().
    • setMinimum

      public void setMinimum​(int minimum)
    • getMaximum

      public int getMaximum()
      Returns:
      maximum value returned by next().
    • setMaximum

      public void setMaximum​(int maximum)
      Set maximum value returned by next().
      If minimum is 5 and maximum is 8 then next() will return random values including 5,6,7 AND 8.