If you want to have a re-usable method to generate a random number, you could create a special class that does that for you:
import java.util.Random;
public class RandomNumberGenerator {
private static final Random RANDOM = new Random();
private RandomNumberGenerator() {
}
//Usage: RandomNumberGenerator.getRandomNumber(10000);
public static int getRandomNumber(int max) {
return RANDOM.nextInt(max);
}
}
This can in turn be used in another class and results can be saved to an arraylist or whatever you like. Example demo:
public class Main {
public static void main(String[] args) {
final List<Integer> randomNumbers = new ArrayList<>();
for (int i = 0; i < 10; i++) {
randomNumbers.add(RandomNumberGenerator.getRandomNumber(10000));
}
}
}
finalfield