Java tutorial
//package com.java2s; import java.util.Random; public class Main { public static String generateToken() { char[] chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".toCharArray(); StringBuilder sb = new StringBuilder(); Random random = new Random(); for (int i = 0; i < 40; i++) { char c = chars[random.nextInt(chars.length)]; sb.append(c); } return sb.toString(); } }