Hi Greg,

Thanks for writing to us, as range are the codePoints you can use it like
below.

RandomStringGenerator generator = new
                RandomStringGenerator.Builder()
                .withinRange('0', 'z').build();

However that will include all the numbers, capital letters, small letters
and some special characters. between (48 to 112)

We are including feature in next release so you can give characters you
want to generate random string, but that will be available in Text 1.2
release.

For now as an alternate you can use below code as well passing it array of
a to z and 0 to 9.

Set<Integer> characters = Stream.of('a', 'b', '1', '2').map(i -> (int)
i).collect(Collectors.toSet());
String str = new RandomStringGenerator.Builder().filteredBy(i ->
characters.contains(i)).build().generate(5);

Let us know if you need more info.

Regards,
Amey

On Tue, Jun 27, 2017 at 8:03 PM, Greg Huber <gregh3...@gmail.com> wrote:

> ​Hello,
>
> How would I use org.apache.commons.text.RandomStringGenerator to replace
> the RandomStringUtils alpha numeric number?
>
> String text = RandomStringUtils.randomAlphanumeric(num);
>
> The docs only show how to use a-z :
>
> RandomStringGenerator generator = new
>                 RandomStringGenerator.Builder()
>                 .withinRange('a', 'z').build();
>
> String text = generator.generate(num);
>
> Cheers
>
> ​
>



-- 

---------------------------------------------------------------------

To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org

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

Reply via email to