I need to generate a random 2 digit number which will be concatenated to the end of a string. The number MUST be 2 digits (i.e. 00-99, nothing <10 is acceptable).
How can this be done using Java libraries in the simplest way possible?
I need to generate a random 2 digit number which will be concatenated to the end of a string. The number MUST be 2 digits (i.e. 00-99, nothing <10 is acceptable).
How can this be done using Java libraries in the simplest way possible?
A pretty simple way would be to generate two random integers separately, and then add them to the end of your string. That way anything from 1-9 would show up as 01-09.
Using this answer, Generating random integers in a specific range, you generate the two integers. Then create an empty string and add the two variables you used to store your random integers.
Psuedocode:
int a = RANDOMNUMBER
int b = RANDOMNUMBER
String number = "" + a + b