Package nxt.addons
Class ReproducibleRandomness
java.lang.Object
nxt.addons.ReproducibleRandomness
- All Implemented Interfaces:
RandomnessSource
The purpose of this class is to make sure all contract runners will generate the same random numbers given the same random seed.
Unfortunately, the default SecureRandom implementation in Java 9+ does not respect this property i.e. given the same random seed
even two different secure random objects in the same process will generate different numbers.
The java.util.Random implementation is reproducible, but is trivial to predict.
We therefore rely on the "SHA1PRNG" algorithm (Java 8 default) which is reproducible and provides reasonable level
of security and interoperability between Java versions.
This class delegates all random number requests to the actual secure random.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondoubles()doubles(double randomNumberOrigin, double randomNumberBound) doubles(long streamSize) doubles(long streamSize, double randomNumberOrigin, double randomNumberBound) longgetSeed()ints()ints(int randomNumberOrigin, int randomNumberBound) ints(long streamSize) ints(long streamSize, int randomNumberOrigin, int randomNumberBound) longs()longs(long streamSize) longs(long randomNumberOrigin, long randomNumberBound) longs(long streamSize, long randomNumberOrigin, long randomNumberBound) booleanvoidnextBytes(byte[] bytes) doublefloatintnextInt()intnextInt(int bound) longnextLong()voidsetSeed(long seed)
-
Constructor Details
-
ReproducibleRandomness
public ReproducibleRandomness()
-
-
Method Details
-
setSeed
public void setSeed(long seed) - Specified by:
setSeedin interfaceRandomnessSource
-
getSeed
public long getSeed()- Specified by:
getSeedin interfaceRandomnessSource
-
nextBytes
public void nextBytes(byte[] bytes) - Specified by:
nextBytesin interfaceRandomnessSource
-
nextInt
public int nextInt()- Specified by:
nextIntin interfaceRandomnessSource
-
nextInt
public int nextInt(int bound) - Specified by:
nextIntin interfaceRandomnessSource
-
nextLong
public long nextLong()- Specified by:
nextLongin interfaceRandomnessSource
-
nextBoolean
public boolean nextBoolean()- Specified by:
nextBooleanin interfaceRandomnessSource
-
nextFloat
public float nextFloat()- Specified by:
nextFloatin interfaceRandomnessSource
-
nextDouble
public double nextDouble()- Specified by:
nextDoublein interfaceRandomnessSource
-
ints
- Specified by:
intsin interfaceRandomnessSource
-
ints
- Specified by:
intsin interfaceRandomnessSource
-
ints
- Specified by:
intsin interfaceRandomnessSource
-
ints
- Specified by:
intsin interfaceRandomnessSource
-
longs
- Specified by:
longsin interfaceRandomnessSource
-
longs
- Specified by:
longsin interfaceRandomnessSource
-
longs
- Specified by:
longsin interfaceRandomnessSource
-
longs
- Specified by:
longsin interfaceRandomnessSource
-
doubles
- Specified by:
doublesin interfaceRandomnessSource
-
doubles
- Specified by:
doublesin interfaceRandomnessSource
-
doubles
- Specified by:
doublesin interfaceRandomnessSource
-
doubles
- Specified by:
doublesin interfaceRandomnessSource
-