Package org.apache.commons.rng.sampling
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 Tsample()Picks one of the items from thecollection passed to the constructor.
-
Constructor Details
-
CollectionSampler
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- ifcollectionis empty.
-
-
Method Details
-
sample
Picks one of the items from thecollection passed to the constructor.- Returns:
- a random sample.
-