Class LagFib
java.lang.Object
io.github.olyutorskii.aletojio.rng.fibo.LagFib
- All Implemented Interfaces:
RndInt32
Lagged Fibonacci Pseudo Random Generator(LFG).
Recurrence relation sequences : X(n) = X(n-j) + X(n-k)
If generation(1,2) given, it generates the so-called Fibonacchi numbers sequence.
Typical generation pairs.
- (1,2)
- (7,10)
- (24,55)
- (353,521)
- (861,1279)
- (9739,23209)
Seed values are mixed well if the number of generations(k,j) are prime to each other.
If polynomial: y = x**k + x**j + 1
is primitive over GF(2),
generator has more long period.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected int
binOp
(int tap1, int tap2) Binary operation between 2 taps.protected void
checkSeeds
(int... initVec) Check seeds.static boolean
hasOdd
(int... iVec) Check whether int array contains odd number or not.int
Return next random number as 32bit int with random sign-bit.void
setSeed
(int... initVec) Set seed.
-
Constructor Details
-
LagFib
public LagFib(int genYounger, int genOlder) throws IndexOutOfBoundsException, IllegalArgumentException Constructor.Number of generation must be greater than 0.
Older generation number must be greater than younger.
- Parameters:
genYounger
- younger past generation X(n-j)genOlder
- older past generation X(n-k)- Throws:
IndexOutOfBoundsException
- Given generation is out of rangeIllegalArgumentException
- older generation is not greater than youger generation
-
-
Method Details
-
hasOdd
Check whether int array contains odd number or not.- Parameters:
iVec
- int array- Returns:
- true if odd number exists.
- Throws:
NullPointerException
- argument is null
-
checkSeeds
Check seeds.- Parameters:
initVec
- seeds- Throws:
IllegalArgumentException
- illegal seeds
-
setSeed
public void setSeed(int... initVec) throws NullPointerException, IndexOutOfBoundsException, IllegalArgumentException Set seed.At least one of the seeds must be odd number.
Seeds must be old-generation length array.
- Parameters:
initVec
- seed array- Throws:
NullPointerException
- argument is nullIndexOutOfBoundsException
- unmatch seeds lengthIllegalArgumentException
- odd number is not be found
-
binOp
protected int binOp(int tap1, int tap2) Binary operation between 2 taps.Just adding.
- Parameters:
tap1
- tap 1sttap2
- tap 2nd- Returns:
- result
-
nextInt32
public int nextInt32()Return next random number as 32bit int with random sign-bit.
-