On Tue, 6 Dec 2022 at 17:22, Gary Gregory <garydgreg...@gmail.com> wrote: > > I agree this should be in rng. > > Does rng duplicate all of the lang APIs such that we can deprecate the lang > methods?
In short, yes. (cd src/main && git grep -c Random) - ArrayUtils - RandomStringUtils - RandomUtils The proposed ArraySampler with shuffle methods for all array types would deprecate ArrayUtils.shuffle. You would have to provide a UniformRandomProvider in place of a java.util.Random. RandomStringUtils is not explicitly deprecated. However the class javadoc states that Commons Text's RandomStringGenerator and, generically, Commons RNG are more suitable for random generation. RandomUtils is already deprecated. It mentions RNG in the header but the functionality is for static thread-safe calls for random numbers. The RandomUtils class is partly deprecated by changing calls from RandomUtils.xxx to ThreadLocalRandom.current().xxx. The class uses ThreadLocalRandom under the hood, but does not act as a pass-through for all methods. It looks like these could be updated to directly use ThreadLocalRandom's implementation: nextLong(long upper) Note: This method in RandomUtils does not check upper > 0 which is a bug. However the bounds for some methods are different, some have extra conditions and some are missing from ThreadLocalRandom. method : lang : ThreadLocalRandom nextBytes(int) : present : NA nextDouble() : [0, MAX_VALUE) : [0, 1) nextDouble(lower, upper) : [lower, upper) | upper > lower >= 0 : upper > lower nextFloat() : [0, MAX_VALUE) : [0, 1) nextFloat(lower, upper) : [lower, upper) | upper > lower >= 0 : NA nextInt() : [0, MAX_VALUE) : [MIN_VALUE, MAX_VALUE] nextInt(upper) : NA : [0, upper) nextInt(lower, upper) : [lower, upper) | upper > lower >= 0 : [lower, upper) | upper > lower nextLong() : [0, MAX_VALUE) : [MIN_VALUE, MAX_VALUE] nextLong(upper) : [0, upper) [no check upper > 0] : [0, upper) nextLong(lower upper) : [lower, upper) | upper > lower >= 0 : [lower, upper) | upper > lower All these methods are in the UniformRandomProvider interface from [rng], including the nextFloat with ranges but with the exception of nextBytes(int count). The generators provide nextBytes(byte[]) and you must supply the array. In this case it may be helpful to document each method with an equivalent from ThreadLocalRandom that provides a thread-safe static call to generate the same output (with the exception that lower bounds can be negative in ThreadLocalRandom). Alex --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org For additional commands, e-mail: dev-h...@commons.apache.org