[Java] 랜덤 알파벳+숫자 생성하기
샘플코드
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public static void main(String[] args) {
int leftLimit = 48; // numeral '0'
int rightLimit = 122; // letter 'z'
int targetStringLength = 13;
Random random = new Random();
String generatedString = random.ints(leftLimit,rightLimit + 1)
.filter(i -> (i <= 57 || i >= 65) && (i <= 90 || i >= 97))
.limit(targetStringLength)
.collect(StringBuilder::new, StringBuilder::appendCodePoint, StringBuilder::append)
.toString();
System.out.println(generatedString);
}
Leave a comment