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

后端 未结 9 1425
北海茫月
北海茫月 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:35

    import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
    ...
    randomAlphabetic(1).toLowerCase()
    

    this gives you a string with single character

提交回复
热议问题