Class RandomStreams


  • public final class RandomStreams
    extends Object
    Utility for creating streams using a source of randomness.
    Since:
    1.5
    • Method Detail

      • generateWithSeed

        public static <T> Stream<T> generateWithSeed​(long streamSize,
                                                     SplittableUniformRandomProvider source,
                                                     RandomStreams.SeededObjectFactory<T> factory)
        Returns a stream producing the given streamSize number of new objects generated using the supplied source of randomness and object factory.

        A long seed is provided for each object instance using the stream position and random bits created from the supplied source.

        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 - if streamSize is negative.
        NullPointerException - if source or factory is null.