Unique ID Generator

 import java.security.SecureRandom;


public class IdGenerator {


    private static final String CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

    private static final int ID_LENGTH = 12;

    private static final SecureRandom RANDOM = new SecureRandom();


    public static String generateUniqueUserId() {

        StringBuilder userId = new StringBuilder(ID_LENGTH);

        for (int i = 0; i < ID_LENGTH; i++) {

            userId.append(CHARACTERS.charAt(RANDOM.nextInt(CHARACTERS.length())));

        }

        return userId.toString();

    }

}

Comments

Popular posts from this blog

Transform values with a stream

Collections Framework

Inspect a collection