Reputation: 33
I'm making a bingo like program in java, I was wondering if it was a ll possible to select a number from a pool, then have it cross it out. I was thinking of putting the 75 (bingo numbers) into an array then have it select it from there, but i cant seem to find a way to get rid of that number once it's selected. for example, i only want to call the number 55 ONCE, then have it gone, or non-accessible from the pool once it's called by my random function.
Thanks Rob
Upvotes: 1
Views: 1983
Reputation: 11
Place all 75 numbers into an array.
Call Arrays.shuffle()
on the array.
Read the array in-order.
Upvotes: 1
Reputation: 15278
http://docs.oracle.com/javase/1.4.2/docs/api/java/util/Collections.html#shuffle%28java.util.List%29
Upvotes: 4
Reputation: 5415
Upvotes: 0
Reputation: 25489
(deleted my previous answer because I misread the question)
Easiest way I can think of to do this is to store them in an ArrayList
, track the size and feed that into a random number generator to randomly access an index and remove after use.
Upvotes: 1