Update LFSR.java
This commit is contained in:
parent
646753d788
commit
6e2c0feddf
@ -3,6 +3,7 @@ package org.warp.commonutils.random;
|
|||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Linear feedback shift register
|
* Linear feedback shift register
|
||||||
@ -58,12 +59,13 @@ public class LFSR implements Iterable<BigInteger> {
|
|||||||
this.taps = primitivePoly.shiftRight(1);
|
this.taps = primitivePoly.shiftRight(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Iterator<BigInteger> iterator() {
|
public LFSRIterator iterator() {
|
||||||
return new LFSRIterator(start);
|
return new LFSRIterator(start);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class LFSRIterator implements Iterator<BigInteger> {
|
public class LFSRIterator implements Iterator<BigInteger> {
|
||||||
// The last one we returned.
|
// The last one we returned.
|
||||||
|
|
||||||
private BigInteger last = null;
|
private BigInteger last = null;
|
||||||
@ -110,6 +112,12 @@ public class LFSR implements Iterable<BigInteger> {
|
|||||||
return last;
|
return last;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BigInteger next(BigInteger last) {
|
||||||
|
this.last = last;
|
||||||
|
next = null;
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void remove() {
|
public void remove() {
|
||||||
throw new UnsupportedOperationException("Not supported.");
|
throw new UnsupportedOperationException("Not supported.");
|
||||||
|
Loading…
Reference in New Issue
Block a user