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 int
getNext()
int
getOffset()
int
getSeed()
int
next()
Return next value in sequence, then generate new value.void
randomize()
Set seed from system time.void
reset()
Reset sequence generator so that it will restart at beginning.void
setNext(int next)
Set next value in sequence.void
setOffset(int offset)
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
-
HailstoneSequence
public HailstoneSequence()
-
-
Method Details
-
next
public int next()Return next value in sequence, then generate new value.- Specified by:
next
in interfaceSequenceGenerator
-
getNext
public int getNext()- Specified by:
getNext
in interfaceSequenceGenerator
- Returns:
- next value in sequence.
-
setNext
public void setNext(int next)Set next value in sequence.- Specified by:
setNext
in interfaceSequenceGenerator
-
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 interfaceSequenceGenerator
-
setSeed
public void setSeed(int seed)Set sequence seed. Following call to next() will return this number.- Specified by:
setSeed
in interfaceSequenceGenerator
-
getSeed
public int getSeed()- Specified by:
getSeed
in interfaceSequenceGenerator
- Returns:
- seed set by setSeed.
-
reset
public void reset()Reset sequence generator so that it will restart at beginning.- Specified by:
reset
in interfaceSequenceGenerator
-
getOffset
public int getOffset()- Returns:
- offset set by setOffset.
-
setOffset
public void setOffset(int offset)
-