Package com.softsynth.jmsl.util
Class HailstoneSequence
java.lang.Object
com.softsynth.jmsl.util.HailstoneSequence
- All Implemented Interfaces:
SequenceGenerator
public class HailstoneSequence extends java.lang.Object implements SequenceGenerator
Generate "Hailstone Sequence" based on an article in
Scientific American FIXME - find reference.
If the previous value is odd, then n= p*3 - 5;
If the previous value is even, then n= p/2 + 1;
If the previous value is odd, then n= p*3 - 5;
If the previous value is even, then n= p/2 + 1;
- Author:
- Phil Burk and Nick Didkovsky
-
Constructor Summary
Constructors Constructor Description HailstoneSequence() -
Method Summary
Modifier and Type Method Description intgetNext()intgetOffset()intgetSeed()intnext()Return next value in sequence, then generate new value.voidrandomize()Set seed from system time.voidreset()Reset sequence generator so that it will restart at beginning.voidsetNext(int next)Set next value in sequence.voidsetOffset(int offset)voidsetSeed(int seed)Set sequence seed.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
HailstoneSequence
public HailstoneSequence()
-
-
Method Details
-
next
public int next()Return next value in sequence, then generate new value.- Specified by:
nextin interfaceSequenceGenerator
-
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
-
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
-
setSeed
public void setSeed(int seed)Set sequence seed. Following call to next() will return this number.- 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
-
getOffset
public int getOffset()- Returns:
- offset set by setOffset.
-
setOffset
public void setOffset(int offset)
-