如何生成随机字母字符串

使用下面的代码生成随机字符串:[code]package org.kodejava.example.commons.lang;

import org.apache.commons.lang.RandomStringUtils;

public class RandomStringUtilsDemo {
public static void main(String[] args) {
//
// Creates a 64 chars length random string of number.
//
String result = RandomStringUtils.random(64, false, true);
System.out.println("random = " + result);

    //
    // Creates a 64 chars length of random alphabetic string.
    //
    result = RandomStringUtils.randomAlphabetic(64);
    System.out.println("random = " + result);

    //
    // Creates a 32 chars length of random ascii string.
    //
    result = RandomStringUtils.randomAscii(32);
    System.out.println("random = " + result);

    //
    // Creates a 32 chars length of string from the defined array of
    // characters including numeric and alphabetic characters.
    //
    result = RandomStringUtils.random(32, 0, 20, true, true, "qw32rfHIJk9iQ8Ud7h0X".toCharArray());
    System.out.println("random = " + result);
}

}[/code]运行结果如下:random = 2377316738997278218735578855577798247976319451877477254850564896 random = wwqbLxlRynIdptAoxuSIfbABRoOFHLyKaFEscrUoBQjAHPOkcIqfHuMnhXVzaLCf random = 6nQ0PJf<#VgIi='&d`*`Ru#i_exMoHXb random = ZGbelXYEiLrlLBXKroCIDJPrevZPIGkD可以用这个生成随机数字。