[
https://issues.apache.org/jira/browse/RNG-140?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17362965#comment-17362965
]
Alex Herbert commented on RNG-140:
----------------------------------
It could. But for the {{int}} case we have a sampler in the sampling package
that does the equivalent algorithm:
{code:java}
DiscreteSampler sampler = DiscreteUniformSampler.of(rng, lower, upper);
{code}
Pending an eventual update to Java 8 it would make more sense to have a sampler
interface that returns a long so we can move to support double, int or long
streams with the sampler as a supplier. Perhaps DiscreteLongSampler or just
LongSampler?
* ContinuousSampler (double)
* DiscreteSampler (int)
* DiscreteLongSampler (long)
* LongSampler (long)
Since the interfaces are functional interfaces (1 method) it would be cleaner
(in Java 8) to have the samplers just implement:
* DoubleSupplier.getAsDouble
* IntSupplier.getAsInt
* LongSupplier.getAsLong
The methods names are not as nice as the current {{sample}}. And we would have
to add the SharedStateSampler support to this:
* SharedStateDoubleSupplier
* SharedStateIntSupplier
* SharedStateLongSupplier
So maybe:
* LongSampler
* SharedStateLongSampler
Then add an additional method to the current DiscreteUniformSampler with long
instead of int arguments:
{code:java}
int lower = ...
int upper = ...
SharedStateDiscreteSampler sampler1 = DiscreteUniformSampler.of(rng, lower,
upper);
SharedStateLongSampler sampler2 = DiscreteUniformSampler.of(rng, (long) lower,
(long) upper);
{code}
Note that the factory method returns the interface type. It was mentioned that
a fluent API would return an instance of the class. If this is to be used in
the future (RNG 2.0) then the factory method should be in its own class. A
future API would be to replace ContinuousSampler and DiscreteSampler and with
the more specific DoubleSampler and IntSampler:
{code:java}
DoubleSampler s1 = UniformDoubleSampler.of(rng, 3.12, 4.23);
IntSampler s2 = UniformIntSampler.of(rng, 32, 45);
LongSampler s3 = UniformLongSampler.of(rng, 100000000000032L, 100000000000045L);
{code}
This cannot be done currently as factory methods are tied to returning
instances of the interface SharedState(Continuous|Discrete)Sampler. So those
interfaces must continue until a major release.
For now I suggest adding:
* LongSampler (interface)
* SharedStateLongSampler (interface)
* UniformLongSampler (sampler that implements the algorithm)
> nextLong(long lo, long hi)
> --------------------------
>
> Key: RNG-140
> URL: https://issues.apache.org/jira/browse/RNG-140
> Project: Commons RNG
> Issue Type: Wish
> Components: sampling
> Reporter: Gilles Sadowski
> Priority: Minor
> Labels: api
>
> Replacement for functionality defined in
> [{{RandomUtils}}|https://gitbox.apache.org/repos/asf?p=commons-math.git;a=blob;f=commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/random/RandomUtils.java;h=60060e71d5bbe1d00878a1f54f8bb1ff88b65f11;hb=HEAD#l293].
--
This message was sent by Atlassian Jira
(v8.3.4#803005)