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.
- All Implemented Interfaces:
ObjectSampler<T>
,SharedStateObjectSampler<T>
,SharedStateSampler<SharedStateObjectSampler<T>>
Sampling from a
Collection
.
Sampling uses UniformRandomProvider.nextInt(int)
.
- Since:
- 1.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionCollection to be sampled from.private final UniformRandomProvider
RNG. -
Constructor Summary
ConstructorsModifierConstructorDescriptionCollectionSampler
(UniformRandomProvider rng, Collection<T> collection) Creates a sampler.private
CollectionSampler
(UniformRandomProvider rng, CollectionSampler<T> source) -
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 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.commons.rng.sampling.ObjectSampler
samples, samples
-
Field Details
-
items
Collection to be sampled from. -
rng
RNG.
-
-
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
- ifcollection
is empty.
-
CollectionSampler
- Parameters:
rng
- Generator of uniformly distributed random numbers.source
- Source to copy.
-
-
Method Details
-
sample
Picks one of the items from thecollection passed to the constructor
.- Specified by:
sample
in 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:
withUniformRandomProvider
in interfaceSharedStateSampler<T>
- Parameters:
rng
- Generator of uniformly distributed random numbers.- Returns:
- the sampler
- Since:
- 1.3
-