public class VMPCRandomGenerator extends java.lang.Object implements RandomGenerator
Modifier and Type | Field and Description |
---|---|
private byte |
n |
private byte[] |
P
Permutation generated by code:
// First 1850 fractional digit of Pi number. |
private byte |
s
Value generated in the same way as
P ; |
Constructor and Description |
---|
VMPCRandomGenerator() |
Modifier and Type | Method and Description |
---|---|
void |
addSeedMaterial(byte[] seed)
Add more seed material to the generator.
|
void |
addSeedMaterial(long seed)
Add more seed material to the generator.
|
void |
nextBytes(byte[] bytes)
Fill bytes with random values.
|
void |
nextBytes(byte[] bytes,
int start,
int len)
Fill part of bytes with random values.
|
private byte n
private byte[] P
// First 1850 fractional digit of Pi number.
byte[] key = new BigInteger("14159265358979323846...5068006422512520511").toByteArray();
s = 0;
P = new byte[256];
for (int i = 0; i < 256; i++) {
P[i] = (byte) i;
}
for (int m = 0; m < 768; m++) {
s = P[(s + P[m & 0xff] + key[m % key.length]) & 0xff];
byte temp = P[m & 0xff];
P[m & 0xff] = P[s & 0xff];
P[s & 0xff] = temp;
}
private byte s
P
;public void addSeedMaterial(byte[] seed)
RandomGenerator
addSeedMaterial
in interface RandomGenerator
seed
- a byte array to be mixed into the generator's state.public void addSeedMaterial(long seed)
RandomGenerator
addSeedMaterial
in interface RandomGenerator
seed
- a long value to be mixed into the generator's state.public void nextBytes(byte[] bytes)
RandomGenerator
nextBytes
in interface RandomGenerator
bytes
- byte array to be filled.public void nextBytes(byte[] bytes, int start, int len)
RandomGenerator
nextBytes
in interface RandomGenerator
bytes
- byte array to be filled.start
- index to start filling at.len
- length of segment to fill.