Skip to content

计算机

随机生成的 30 个小写字母

英文字母共有 26 个,英文字母大小写分别有 26 个大写字母、26 个小写字母。

a 的 unicode 是 97,b 的 unicode 是 98,依次增大,最后一个字母 z 的 unicode 是 122。

A 的 unicode 是 65,B 的 unicode 是 66,依次增大,最后一个大写字母 Z 的编号是 90。

如果使用 Java 语言,那么这样写来生成随机的 30 个小写字母:

java
Random rand = new Random();

for (int i = 0; i < 30; i++) {
  const world = (char)(rand.nextInt(26) + 97) + "";
}

如果使用 js 语言:

js
// 生成大写字母 A 的 Unicode 值为 65
function generateBig_1(){
    var str = [];
    for(var i = 65;i < 91; i ++){
        str.push(String.fromCharCode(i));
    }
    return str;
}
// 生成大写字母 a 的 Unicode 值为 97
function generateSmall_1(){
    var str = [];
    for(var i = 97;i < 123; i++){
        str.push(String.fromCharCode(i));
    }
    return str;
}

Released under the MIT License.