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();
But since this only generates numbers, what do I need to do to apply this to letters?
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();
But since this only generates numbers, what do I need to do to apply this to letters?
use the ascii value of the letters to generate the random number.
alter version of @Michael Barker
this gives you a string with single character
To randomly select a letter from (a- z) I would do the following:
Since Random.nextInt() generates a value from 0 to 25, you need only add an offset of 'a' to produce the lowercase letters.