On Thu, Jun 29, 2017 at 5:31 PM, Gilles <gil...@harfang.homelinux.org>
wrote:

> On Thu, 29 Jun 2017 11:52:30 +0000, Amey Jadiye wrote:
>
>> Hi All,
>>
>> I'd apritiate if someone can provide valuable inputs / suggestions /
>> improvements.
>>
>> I think this will be value added to RandomStringGenerator.
>>
>> Regards,
>> Amey
>>
>> On Tue, Jun 27, 2017, 11:40 PM Amey Jadiye <ameyjad...@gmail.com> wrote:
>>
>> Hi All,
>>>
>>> With below reference user asked whether he can use alpha numeric string ?
>>>  we can do that easily by overloading .withinRange(char[][])
>>> where my vision is to pass multiple pairs of min max characters. so we
>>> can
>>> pas {'0','9'} and {'a','z'}, OR any similar alternative where we can pass
>>> pairs of range.
>>>
>>> i.e.
>>>
>>> RandomStringGenerator generator = new
>>>                 RandomStringGenerator.Builder()
>>>                 .withinRange({'0','9'}, {'a','z'}).build();
>>>
>>>
>>> What do you guys think  ?
>>>
>>
> I wonder whether handling ranges belong to this class (or its builder).
> At first sight, it seems preferable that ranges are transformed (into
> an array of characters) before being passed to the generator builder.
>
> Regards,
> Gilles
>
>
Ok, In that case TEXT-93 will take care of what you are thinking. that to
simply expand range and create array of characters however that is little
painful for application developers.

What I'm pushing for is pass just array of (min, max) pairs and API will
take care of it, that will be less painful and easy to use API.

Ex.

char [][]  ranges = {{'0','9'},{'A','Z',{'a','z'}}};

RandomStringGenerator generator = new
                RandomStringGenerator.Builder()
                .withinRange(ranges).build();



>
>
>>> Regards,
>>> Amey
>>>
>>> ---------- Forwarded message ----------
>>> From: Amey Jadiye <ameyjad...@gmail.com>
>>> Date: Tue, Jun 27, 2017 at 10:57 PM
>>> Subject: Re: [text] - using RandomStringGenerator for alpha numeric
>>> To: Commons Users List <u...@commons.apache.org>, gregh3...@gmail.com
>>>
>>>
>>> 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
>
>


-- 

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

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

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

Reply via email to