ee.bitweb.core.util.StringUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spring-core Show documentation
Show all versions of spring-core Show documentation
Bitweb Spring Boot Java Core Library
The newest version!
package ee.bitweb.core.util;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import java.security.SecureRandom;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class StringUtil {
private static final String CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
private static final SecureRandom RANDOM = new SecureRandom();
public static String random(int length) {
var sb = new StringBuilder();
while (sb.length() < length) {
var index = RANDOM.nextInt(CHARS.length());
sb.append(CHARS.charAt(index));
}
return sb.toString();
}
}