Answer the question
In order to leave comments, you need to log in
How to make a generator of random letters and numbers in java?
How to make a generator of random numbers and letters in java?
For example, so that each time, completely random numbers are displayed, and letters, for example 8, or 16, random numbers? and letters?
Answer the question
In order to leave comments, you need to log in
int length = 16;
Random r = new Random();
String s = r.ints(48, 122)
.filter(i -> (i < 57 || i > 65) && (i < 90 || i > 97))
.mapToObj(i -> (char) i)
.limit(length)
.collect(StringBuilder::new, StringBuilder::append, StringBuilder::append)
.toString();
So I think it will be clearer.
import java.util.Random;
char[] array = new char[8];
int rand;
Random r = new Random();
for (int i = 0; i< 8; i++) {
rand = r.nextInt(127) + 1; //тут менять нужные диапазоны ((max - min) + 1) + min (см ASCII)
array[i] = (char)rand;
}
for(char c : array)
System.out.println(c);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question