获取随机数:
int i= (int) (100*Math.random());
System.out.println(i);
获取随机字母:
for (int i = 0; i < 4000; i++) { String str = ""; for (int j = 0; j < 6; j++) { str = str + (char) (Math.random() * 26 + 'a'); } System.out.println(str); }获取随机汉字:String str = ""; for (int i = 0; i < 6; i++) { str += (char) (0x4e00 + (int) (Math.random() * (0x9fa5 - 0x4e00 + 1))); } System.out.println(str);
博客展示了在Java中获取随机数的代码,通过Math.random()方法生成0 - 100的随机整数并打印输出,还提及了获取随机字母,但未给出具体代码。
2889

被折叠的 条评论
为什么被折叠?



