[ 
https://issues.apache.org/jira/browse/RNG-145?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17362980#comment-17362980
 ] 

Alex Herbert commented on RNG-145:
----------------------------------

I am OK with this. I think this is valid:

{code:java}
public static SharedStateContinuousSampler of(UniformRandomProvider rng,
                                              double lo,
                                              double hi,
                                              boolean excludeBounds) {
{code}

Currently the underlying nextDouble() method typically returns in the interval 
[0, 1). So the current ContinuousUniformSampler will return in the interval 
[lower, upper). The sampler is robust to a swap of the arguments so you can get 
the alternative (lower, upper] by swapping the arguments to the constructor.

The sample is generated using:

{code:java}
final double u = rng.nextDouble();
return u * hi + (1 - u) * lo;
{code}

So if the nextDouble() does return either 0 or 1 you get one of the bounds.

The current method in Commons Math trusts the implementation of nextDouble does 
not return 1 and only checks for 0.

To ensure we generate in the open interval (lower, upper) I think requires not 
using (trusting) nextDouble() and instead using nextLong() and eliminating 0 
from the call to (nextLong() >>> 11). From the 2^53 -1 numbers that are left 
you can create a double in (0, 1).




> "ContinuousUniformSampler" with both bounds excluded
> ----------------------------------------------------
>
>                 Key: RNG-145
>                 URL: https://issues.apache.org/jira/browse/RNG-145
>             Project: Commons RNG
>          Issue Type: New Feature
>          Components: sampling
>            Reporter: Gilles Sadowski
>            Priority: Major
>             Fix For: 1.4
>
>
> In class {{RandomUtils}}, Commons Math provides
> {code}
> public double nextUniform(double lo, double hi) { /* ... */ }
> {code}
> where both bounds are excluded.
> Should the feature be added to {{ContinuousUniformSampler}}?



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to