com.softsynth.jmsl.util
Class HailstoneSequence

java.lang.Object
  extended by 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;

Author:
Phil Burk and Nick Didkovsky

Constructor Summary
HailstoneSequence()
           
 
Method Summary
 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 Detail

HailstoneSequence

public HailstoneSequence()
Method Detail

next

public int next()
Return next value in sequence, then generate new value.

Specified by:
next in interface SequenceGenerator

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

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

setSeed

public void setSeed(int seed)
Set sequence seed. Following call to next() will return this number.

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

getOffset

public int getOffset()
Returns:
offset set by setOffset.

setOffset

public void setOffset(int offset)