随机生成26个字母中(一个或多个)的字母

转自:

小知识:随机生成26个字母中(一个或多个)的字母

package com.test1;

public class Test3 {

    public static void main(String[] args) {
        
        //需要生成几位
        int n = 1;
        //最终生成的字符串
        String str = "";
        for (int i = 0; i < n; i++) {
            str = str + (char)(Math.random()*26+'a');
        }
        
        System.out.println(str);
    }
}


/*
 特别注意的点:
    1, ‘A’ 是随机生成大写的26个随机字母
    2, ‘a’ 是随机生成小写的26个随机字母
    3, n 的值变化,是生成多少位随机数 n = 1,则随机生成一位; n= 2,则随机生成2位,依次类推…
*/
原文地址:https://www.cnblogs.com/libin6505/p/10155657.html