T - Type of items in the collection.SharedStateSampler<CollectionSampler<T>>public class CollectionSampler<T> extends java.lang.Object implements SharedStateSampler<CollectionSampler<T>>
Collection.
Sampling uses UniformRandomProvider.nextInt(int).
| Constructor | Description |
|---|---|
CollectionSampler(org.apache.commons.rng.UniformRandomProvider rng,
java.util.Collection<T> collection) |
Creates a sampler.
|
| Modifier and Type | Method | Description |
|---|---|---|
T |
sample() |
Picks one of the items from the
collection passed to the constructor. |
CollectionSampler<T> |
withUniformRandomProvider(org.apache.commons.rng.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.
|
public CollectionSampler(org.apache.commons.rng.UniformRandomProvider rng, java.util.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.java.lang.IllegalArgumentException - if collection is empty.public T sample()
collection passed to the constructor.public CollectionSampler<T> withUniformRandomProvider(org.apache.commons.rng.UniformRandomProvider rng)
withUniformRandomProvider in interface SharedStateSampler<T>rng - Generator of uniformly distributed random numbers.Copyright © 2016–2019 The Apache Software Foundation. All rights reserved.