Package com.softsynth.jmsl.util
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 intchoose(int numChoices)intgetMaximum()intgetMinimum()intgetNext()intgetSeed()intnext()Generate next value.voidrandomize()Set seed from system time.voidreset()Reset sequence generator so that it will restart at beginning.voidsetMaximum(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.voidsetMinimum(int minimum)voidsetNext(int next)Set next value in sequence.voidsetSeed(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:
randomizein interfaceSequenceGenerator
-
choose
public int choose(int numChoices)- Returns:
- random number between 0 and numChoices-1
-
next
public int next()Generate next value.- Specified by:
nextin interfaceSequenceGenerator- Returns:
- next value in sequence.
-
getNext
public int getNext()- Specified by:
getNextin interfaceSequenceGenerator- Returns:
- next value in sequence.
-
setNext
public void setNext(int next)Set next value in sequence.- Specified by:
setNextin interfaceSequenceGenerator
-
setSeed
public void setSeed(int seed)Set sequence seed.- Specified by:
setSeedin interfaceSequenceGenerator
-
getSeed
public int getSeed()- Specified by:
getSeedin interfaceSequenceGenerator- Returns:
- seed set by setSeed.
-
reset
public void reset()Reset sequence generator so that it will restart at beginning.- Specified by:
resetin interfaceSequenceGenerator
-
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.
-