T - Type of items in the collection.public class CollectionSampler<T> extends Object implements SharedStateObjectSampler<T>
Collection.
Sampling uses UniformRandomProvider.nextInt(int).
| Constructor and Description |
|---|
CollectionSampler(UniformRandomProvider rng,
Collection<T> collection)
Creates a sampler.
|
| Modifier and Type | Method and Description |
|---|---|
T |
sample()
Picks one of the items from the
collection passed to the constructor. |
CollectionSampler<T> |
withUniformRandomProvider(UniformRandomProvider rng)
Create a new instance of the sampler with the same underlying state using the given
uniform random provider as the source of randomness.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitsamples, samplespublic CollectionSampler(UniformRandomProvider rng, Collection<T> collection)
rng - Generator of uniformly distributed random numbers.collection - Collection to be sampled.
A (shallow) copy will be stored in the created instance.IllegalArgumentException - if collection is empty.public T sample()
collection passed to the constructor.sample in interface ObjectSampler<T>public CollectionSampler<T> withUniformRandomProvider(UniformRandomProvider rng)
withUniformRandomProvider in interface SharedStateSampler<SharedStateObjectSampler<T>>rng - Generator of uniformly distributed random numbers.Copyright © 2016–2022 The Apache Software Foundation. All rights reserved.