Class CollectionSampler<T>

java.lang.Object
org.apache.commons.rng.sampling.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
  • Constructor Summary

    Constructors 
    Constructor Description
    CollectionSampler​(UniformRandomProvider rng, java.util.Collection<T> collection)
    Creates a sampler.
  • 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 Details

    • 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.
  • Method Details