commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sebb <>
Subject [LANG] 2.5 Random (mis)behaviour
Date Fri, 05 Feb 2010 15:15:29 GMT
I'm hopefully near to finding a version of nextLong(long) that
distributes the numbers better.
There's no such functionality in Random (even in Java 6) so that might
even be a useful addition for Lang3.

But there are some other aspects of RandomUtils and JVMRandom classes
that seem plain wrong in the current 2.4 release:

RandomUtils.nextInt() returns a number in the range [0,Integer.MAX_VALUE)


RandomUtils.nextInt(Random) returns a number in the range

(unless Random is JVMRandom of course)

Similarly for nextLong().

This is not documented for 2.4 and seems like an accident of the
original implementation, rather than a conscious design decision. I've
added some Javadoc to trunk to document the current behaviour, but I
am now wondering whether it would be OK to fix the behaviour so it
agrees with the 2.4 Javadoc?

Also, given that JVMRandom now relies on a static copy of Random, it
would be trivial to implement some of the missing functionality, such

    public static void nextBytes(byte[]);
    public static synchronized double nextGaussian();

with corresponding changes to the instance methods in JVMRandom.

Should this be done, or is it better to leave the methods unimplemented?

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message