+ 1

How can I choose random numbers but only from some selected numbers like 1, 2 and 3.

This question if from JAVA... Edit: And one more thing please in also want to add MIN and MAX in it...

26th Sep 2020, 3:39 AM
Dhruvan Rai
Dhruvan Rai - avatar
4 Answers
+ 4
Dhruvan Rai here is a small code I made both with just a random number and the second part is an array randomized https://code.sololearn.com/crAqBoad9u7L/?ref=app
26th Sep 2020, 6:38 AM
BroFar
BroFar - avatar
+ 3
Make an array of the selected numbers and let the random number generator pick any array element randomly.
26th Sep 2020, 3:44 AM
Arsenic
Arsenic - avatar
+ 2
List<Integer> lista = Arrays.asList(1, 2, 3, 4, 5); Random aleatorio = new Random(); int r = lista.get(aleatorio.nextInt(lista.size())); System.out.println(r);
26th Sep 2020, 4:09 AM
Yaniel Aragon
Yaniel Aragon - avatar
+ 1
Rai ji jay Prasuram
27th Sep 2020, 3:27 AM
Chandra Mani
Chandra Mani - avatar