I want to random 5 values in my arraylist < BigInteger >.
I will first ask for a input for a value. the value can be from 1-∞.
I realized a problem with code is that, if I enter a value >= 500000, the program will start to throw heap space error. How can I resolve this?
public static void main(String[] args) {
BigInteger p;
p = readBigInteger("Enter a value ");
ArrayList<BigInteger> list = new ArrayList<BigInteger>();
for (BigInteger bi = BigInteger.valueOf(1); bi.compareTo(p) <= 0; bi = bi.add(BigInteger.ONE)) {
list.add(bi);
}
Collections.shuffle(list);
for (BigInteger bi = BigInteger.valueOf(1); bi.compareTo(new BigInteger("5")) <= 0; bi = bi.add(BigInteger.ONE)) {
Integer a = bi.intValue();
System.out.println(list.get(a));
}
}