In Java how do you randomly select a letter (a-z)?

后端 未结 9 1372
北海茫月
北海茫月 2021-01-04 03:50

If I want to randomly select a letter between a and z, I assume I have to use the Random class:

Random rand = new Random();

Bu

9条回答
  •  一整个雨季
    2021-01-04 04:23

    why assume to use Random instead of Math.random? You can even make the code shorter...

    public static char genChar(){
        return (char)(Math.random()*26 + 'a');
    }
    

提交回复
热议问题