Java tutorial
//package com.java2s; //License from project: Apache License import java.security.SecureRandom; public class Main { /** * The length of the pseudo random constructed string */ private static final int SEED_LENGTH = 64; /** * The space used by {@link java.util.Random#nextInt(int)} */ private static final int SEED_SPACE = 96; /** * Generate a random string (used for database encryption) * * @return a random string of 64 characters */ public static String generateRandomString() { SecureRandom generator = new SecureRandom(); StringBuilder randomStringBuilder = new StringBuilder(); char tempChar; int numbChar = 0; while (numbChar < SEED_LENGTH) { tempChar = (char) (generator.nextInt(SEED_SPACE) + 32); boolean num = tempChar >= 48 && tempChar < 58;//0-9 boolean cap = tempChar >= 65 && tempChar < 91;//A-Z boolean lower = tempChar >= 65 && tempChar < 91;//a-z if (num || cap || lower) { randomStringBuilder.append(tempChar); numbChar++; } } return randomStringBuilder.toString(); } }