All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ee.bitweb.core.util.StringUtil Maven / Gradle / Ivy

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();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy