Package org.apache.commons.rng.core.util
Class RandomStreams
- java.lang.Object
-
- org.apache.commons.rng.core.util.RandomStreams
-
public final class RandomStreams extends Object
Utility for creating streams using a source of randomness.- Since:
- 1.5
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
RandomStreams.SeededObjectFactory<T>
A factory for creating objects using a seed and a using a source of randomness.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> Stream<T>
generateWithSeed(long streamSize, SplittableUniformRandomProvider source, RandomStreams.SeededObjectFactory<T> factory)
Returns a stream producing the givenstreamSize
number of new objects generated using the suppliedsource
of randomness and objectfactory
.
-
-
-
Method Detail
-
generateWithSeed
public static <T> Stream<T> generateWithSeed(long streamSize, SplittableUniformRandomProvider source, RandomStreams.SeededObjectFactory<T> factory)
Returns a stream producing the givenstreamSize
number of new objects generated using the suppliedsource
of randomness and objectfactory
.A
long
seed is provided for each object instance using the stream position and random bits created from the suppliedsource
.The stream supports parallel execution by splitting the provided
source
of randomness. Consequently objects in the same position in the stream created from a sequential stream may be created from a different source of randomness than a parallel stream; it is not expected that parallel execution will create the same final collection of objects.- Type Parameters:
T
- the object type- Parameters:
streamSize
- Number of objects to generate.source
- A source of randomness used to initialise the new instances; this may be split to provide a source of randomness across a parallel stream.factory
- Factory to create new instances.- Returns:
- a stream of objects; the stream is limited to the given
streamSize
. - Throws:
IllegalArgumentException
- ifstreamSize
is negative.NullPointerException
- ifsource
orfactory
is null.
-
-