1@Test
2public void givenUsingJava8_whenGeneratingRandomAlphanumericString_thenCorrect() {
3 int leftLimit = 48; // numeral '0'
4 int rightLimit = 122; // letter 'z'
5 int targetStringLength = 10;
6 Random random = new Random();
7
8 String generatedString = random.ints(leftLimit, rightLimit + 1)
9 .filter(i -> (i <= 57 || i >= 65) && (i <= 90 || i >= 97))
10 .limit(targetStringLength)
11 .collect(StringBuilder::new, StringBuilder::appendCodePoint, StringBuilder::append)
12 .toString();
13
14 System.out.println(generatedString);
15}
16