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

org.testcontainers.utility.Base58 Maven / Gradle / Ivy

There is a newer version: 1.20.3
Show newest version
package org.testcontainers.utility;

import java.security.SecureRandom;

/**
 * Utility class for creation of random strings of 58 easy-to-distinguish characters.
 */
public class Base58 {

    private static final char[] ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz".toCharArray();

    private static final SecureRandom RANDOM = new SecureRandom();

    public static String randomString(int length) {
        char[] result = new char[length];

        for (int i = 0; i < length; i++) {
            char pick = ALPHABET[RANDOM.nextInt(ALPHABET.length)];
            result[i] = pick;
        }

        return new String(result);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy