commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gilles <>
Subject Re: [text] RandomStringGenerator as replacement for RandomStringUtils
Date Tue, 20 Jun 2017 12:22:44 GMT

On Tue, 20 Jun 2017 00:12:58 -0400, Wilson MacGyver wrote:
> Hi,
> After upgrading to commons-lang 3.6 I noticed RandomStringUtils has 
> been
> deprecated in favor of RandomStringGenerator in commons-text
> currently I'm using it by passing a character array that has a mix of
> characters and symbols. I'm also using SecureRandom as the random 
> source
> I'm not at all clear on how to do this in RandomStringGenerator.
> I notice in the builder you can pass a range, but this implies 
> characters
> you want to use must be continuous within unicode. The only thing I 
> can
> think of is to then
> use filteredBy to filter out characters that I don't want?

That would not be very efficient.
Perhaps we should implement a "selectFrom" feature:
   RandomStringGenerator gen = new RandomStringGenerator.Builder()

> At first glance, it also looks like usingRandom() only works with the
> apache common RNG?

No. You can pass any class that implement the "TextRandomProvider"
interface (there is an example in the "RandomStringGeneratorTest"
unit test class).

If you use Java 8, you can also do:
   final SecureRandom rand = new SecureRandom();
   RandomStringGenerator gen = new RandomStringGenerator.Builder()


> Thanks

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

View raw message