Skip to content

Commit

Permalink
Add exclusion functionality to the random string method in SysFuncUti…
Browse files Browse the repository at this point in the history
…ls (#868)
  • Loading branch information
IiiinSea authored Jul 29, 2024
2 parents 39dbd00 + ceee5a8 commit 2e1a60b
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,15 @@ private static String randomString(String[] funcParams){
if (range <= 0) {
return "";
}
String exclusion = (funcParams.length > 1)?funcParams[1]:null;
ThreadLocalRandom localRandom = ThreadLocalRandom.current();
StringBuilder builder = new StringBuilder();
for (int i = 0; i < range; i++) {
builder.append(charSeeds[localRandom.nextInt(charSeeds.length)]);
int n = 0;//prevent infinite loops
while (builder.length() < range && n++ < 10000){
char randomChar = charSeeds[localRandom.nextInt(charSeeds.length)];
if(exclusion == null || !exclusion.contains(String.valueOf(randomChar))){
builder.append(randomChar);
}
}
return builder.toString();
}
Expand Down

0 comments on commit 2e1a60b

Please sign in to comment.