Java tutorial
//package com.java2s; import java.util.Random; public class Main { private final static String NONCE_SAMPLE = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; private static String generateNonce(int length) { Random random = new Random(System.currentTimeMillis()); if (length < 10) length = 10; int MAX_LEN = NONCE_SAMPLE.length(); StringBuffer buf = new StringBuffer(); for (int i = 0; i < length; i++) { buf.append(NONCE_SAMPLE.charAt(random.nextInt(MAX_LEN))); } return buf.toString(); } }