This question already has an answer here:
- Retrieving a random item from ArrayList 11 answers
i tried to get a random value from 50 to 100 of an object but i didn't find a solution! any help please?
public class OneArmedBandit implements Item {
Random rand = new Random();
private List<Integer> Item = new ArrayList<Integer>();
public OneArmedBandit(List<Integer> ItemList) {
this.Item=ItemList;
}
public int AnyItem(List<Integer> ItemList) {
Random rand = new Random();
int index = ItemList.get(rand.nextInt(ItemList.size()));
return ItemList.get(index);
}
public List<Integer> getListItem(){
return this.Item;
}
}
Aucun commentaire:
Enregistrer un commentaire