|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectbb.science.Lfsr
public class Lfsr
Implements a linear feedback shift register (LFSR). The register's size (an int named n) may be any value from 2 thru 32. Any starting state of the register (called the seed) may also be specifed.
This class is not multithread safe.
Nested Class Summary | |
---|---|
static class |
Lfsr.UnitTest
See the Overview page of the project's javadocs for a general description of this unit test class. |
Field Summary | |
---|---|
private static int |
count
|
private int |
mask
|
private int |
n
|
private static Random |
random
|
private int |
register
|
private int |
taps
|
Constructor Summary | |
---|---|
Lfsr(int n)
Convenience constructor that simply calls . |
|
Lfsr(int n,
int seed)
Fundamental constructor. |
Method Summary | |
---|---|
int |
advance()
Convenience method that simply returns advance (1). |
int |
advance(long numberTransitions)
Advances the internal state of this instance by numberTransitions. |
int |
getMask()
Accessor for mask . |
int |
getRegister()
Accessor for register . |
int |
getTaps()
Accessor for taps . |
private static int |
makeMask(int n)
Returns an int with all the n low order bits set to 1 and all the high order bits set to 0. |
static int |
makeSeedNext(int n)
Returns the next seed suitable for an LFSR of size n. |
static int |
makeSeedRandom(int n)
Returns a pseudo-random seed suitable for an LFSR of size n. |
private static int |
makeTaps(int n)
Returns an int which can function as the taps of n order maximal LFSR. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final Random random
private static int count
private final int n
private final int mask
private final int taps
private int register
Constructor Detail |
---|
public Lfsr(int n) throws IllegalArgumentException
Lfsr
(n, 1)
.
IllegalArgumentException
- if n < 2 or n > 32public Lfsr(int n, int seed) throws IllegalArgumentException
IllegalArgumentException
- if n < 2 or n > 32;
if seed == 0 or has high bits (i.e. beyond the nth bit) setMethod Detail |
---|
public static int makeSeedNext(int n) throws IllegalArgumentException
constructor
.
IllegalArgumentException
- if n < 0 or n > 32public static int makeSeedRandom(int n) throws IllegalArgumentException
constructor
.
This method is an
IllegalArgumentException
- if n < 0 or n > 32private static int makeMask(int n) throws IllegalArgumentException
IllegalArgumentException
- if n < 0 or n > 32private static int makeTaps(int n) throws IllegalArgumentException
IllegalArgumentException
- if n < 2 or n > 32public int getMask()
mask
.
public int getTaps()
taps
.
public int getRegister()
register
.
public int advance()
advance
(1).
public int advance(long numberTransitions) throws IllegalArgumentException
Ignoring an initial argument check and a final return statement,
this method is essentially 2 lines of code: a loop head and its body.
The loop body involves 6 bitwise and/or unary int operators, so it is very simple and fast.
In spite of the simplicity of the computation, the LFSR internal state
(stored in the register
field) is pseudo-random.
It should be impossible for a smart compiler to cut many corners and avoid doing the computations.
IllegalArgumentException
- if numberTransitions < 0
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |