Class CollectionSampler<T>
java.lang.Object
org.apache.commons.rng.sampling.CollectionSampler<T>
- Type Parameters:
T- Type of items in the collection.
- All Implemented Interfaces:
ObjectSampler<T>, SharedStateObjectSampler<T>, SharedStateSampler<SharedStateObjectSampler<T>>
Sampling from a
Collection.
Sampling uses UniformRandomProvider.nextInt(int).
- Since:
- 1.0
-
Constructor Summary
ConstructorsConstructorDescriptionCollectionSampler(UniformRandomProvider rng, Collection<T> collection) Creates a sampler. -
Method Summary
Modifier and TypeMethodDescriptionsample()Picks one of the items from thecollection passed to the constructor.Create a new instance of the sampler with the same underlying state using the given uniform random provider as the source of randomness.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ObjectSampler
samples, samples
-
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:
IllegalArgumentException- ifcollectionis empty.
-
-
Method Details
-
sample
Picks one of the items from thecollection passed to the constructor.- Specified by:
samplein interfaceObjectSampler<T>- Returns:
- a random sample.
-
withUniformRandomProvider
Create a new instance of the sampler with the same underlying state using the given uniform random provider as the source of randomness.- Specified by:
withUniformRandomProviderin interfaceSharedStateSampler<T>- Parameters:
rng- Generator of uniformly distributed random numbers.- Returns:
- the sampler
- Since:
- 1.3
-