Class CollectionSampler<T>

  • Type Parameters:
    T - Type of items in the collection.

    public class CollectionSampler<T>
    extends java.lang.Object
    Sampling from a Collection.

    Sampling uses UniformRandomProvider.nextInt(int).

    Since:
    1.0
    • Method Summary

      Modifier and Type Method Description
      T sample()
      Picks one of the items from the collection passed to the constructor.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CollectionSampler

        public CollectionSampler​(UniformRandomProvider rng,
                                 java.util.Collection<T> collection)
        Creates a sampler.
        Parameters:
        rng - Generator of uniformly distributed random numbers.
        collection - Collection to be sampled. A (shallow) copy will be stored in the created instance.
        Throws:
        java.lang.IllegalArgumentException - if collection is empty.