Class StreamBackedRandom
- java.lang.Object
-
- java.util.Random
-
- edu.berkeley.cs.jqf.fuzz.guidance.StreamBackedRandom
-
- All Implemented Interfaces:
Serializable
public class StreamBackedRandom extends Random
This class extendsRandom
to act as a generator of "random" values, which themselves are read from a static file. The file-backed random number generator can be used for tuning the "random" choices made by variousjunit-quickcheck
generators using a mutation-based genetic algorithm, in order to maximize some objective function that can be measured from the execution of each trial, such as code coverage.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description StreamBackedRandom(InputStream source)
Constructs a stream-backed random generator.StreamBackedRandom(InputStream source, int leadinBytesToIgnore)
Convenience constructor for use with the junit-quickcheck framework.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
getTotalBytesRead()
int
next(int bits)
Generates upto 32 bits of random data for internal use by the Random class.byte
nextByte()
int
nextInt(int bound)
short
nextShort()
-
-
-
Constructor Detail
-
StreamBackedRandom
public StreamBackedRandom(InputStream source)
Constructs a stream-backed random generator. Also sets the seed of the underlying pseudo-random number generator deterministically to zero.- Parameters:
source
- a generator of "random" bytes
-
StreamBackedRandom
public StreamBackedRandom(InputStream source, int leadinBytesToIgnore)
Convenience constructor for use with the junit-quickcheck framework. The junit-quickcheck SourceOfRandomness annoyingly reads 8 bytes of random data as soon as it is instantiated, only to configure its own seed. As the seed is meaningless here, the 8 bytes get wasted. For this purpose, this constructor allows specifying how many bytes of requested random data to skip before starting to read from file.- Parameters:
source
- a generator of "random" bytesleadinBytesToIgnore
- the number of leading bytes to ignore
-
-
Method Detail
-
next
public int next(int bits)
Generates upto 32 bits of random data for internal use by the Random class.Attempts to read up to 4 bytes of data from the input file, and returns the requested lower order bits as a pseudo-random value.
If end-of-file is reached before reading 4 bytes, an
IllegalStateException
is thrown.- Overrides:
next
in classRandom
- Parameters:
bits
- the number of random bits to retain (1 to 32 inclusive)- Returns:
- the integer value whose lower
bits
bits contain the next random data available in the backing source - Throws:
IllegalStateException
- if EOF has already been reached
-
nextByte
public byte nextByte()
-
nextShort
public short nextShort()
-
getTotalBytesRead
public int getTotalBytesRead()
-
-