On 8/5/12 5:30 PM, Gilles Sadowski wrote:
>>>> [...]
>>>> The original code above illustrates the convenience of being able to
>>>> just make direct calls to randomData.nextXxx, which is why this
>>>> class exists ;)
>>> As I wrote in another post, I'm not against the convenience methods. But
>>> IMO, they should be located in a new "DistributionUtils" class.
>> Why?  RandomData is pretty descriptive and exactly what these
>> methods do.  They generate random data.
> Fine...
> But can we plan to merge "RandomData" and "RandomDataImpl"?

Definitely want to do this.  Unfortunately, it is incompatible
change.  I guess we could create a new class named something else,
deprecate both of the above and have RandomDataImpl delegate to the
new class.  How about RandomDataGenerator in the random package as
the new class?
>
>>> And we should also find a way to remove the code duplication (in the
>>> distribution's "sample()" method and in the corresponding "next..." method).
>> +1 - the implementations can be moved.   When I last looked
>> carefully at this, the distribution methods were delegating to impls
>> in RandomDataImpl.  What we have agreed is to move the impls into
>> the distribution classes for the basic sampling methods.  That
>> should not be too hard to do.  I will do that if no one beats me to it.
> I did it in r1363604.
> What still needs to be done is redirect the "next..." to the "sample()"
> method of the appropriate distribution.
> But I had already raised the issue of efficiency: each call to e.g.
>   nextInt(p, q)
> will entail the instantiation of a UniformRealDistribution object.
>
> What could be done is 
> 1. create a static method in the distribution class
> 2. have the "sample()" method call that one
>
> ---
> public class UniformRealDistribution extends ... {
>   // ...
>
>   public static int nextInt(RandomGenerator rng,
>                             int a,
>                             int b) {
>       final double u = rng.nextDouble();
>       return u * b + (1 - u) * a;
>   }
>
>   public int sample() {
>     // Here "random", "lower" and "upper" are instance variables.
>     return nextInt(random, lower, upper);
>   }
> }
> ---
>
> And "nextInt" from "RandomDataImpl" would also be redirected to the static
> method in the distribution class:
>
> ---
> import org.apache.commons.math3.distribution.UniformRealDistribution;
>
> public class RandomDataImpl ... {
>   // ...
>
>   public int nextInt(int lower, int upper) {
>     return UniformRealDistribution.nextInt(getRan(), lower, upper);
>   }
> }
> ---
>
> OK?
>
>
> Gilles
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
> For additional commands, e-mail: dev-h...@commons.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org

Reply via email to