garydgregory commented on PR #125:
URL: https://github.com/apache/commons-text/pull/125#issuecomment-3094498098
Hello @ijliym
Instead of breaking compatiblity and leading to surprising bugs for our
existing users, I've added
`org.apache.commons.text.RandomStringGenerator.Builder.setAccumulate(boolean)`
Use it like this:
```java
final char[] punctuation = ArraySorter
.sort(new char[] { '!', '"', '#', '$', '&', '\'', '(', ')',
',', '.', ':', ';', '?', '@', '[', '\\', ']', '^', '_', '`', '{', '|', '}', '~'
});
final RandomStringGenerator generator =
RandomStringGenerator.builder()
.setAccumulate(true)
.withinRange('a', 'z')
.withinRange('A', 'Z')
.withinRange('0', '9')
.selectFrom(punctuation)
.get();
final String randomText = generator.generate(10);
for (final char c : randomText.toCharArray()) {
assertTrue(Character.isLetter(c) || Character.isDigit(c) ||
Arrays.binarySearch(punctuation, c) >= 0);
}
```
The above is from
`org.apache.commons.text.RandomStringGeneratorTest.testPasswordExample()`
HTH
(Closing PR)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]