()
| 68 | |
| 69 | // return a random item (but do not remove it) |
| 70 | public Item sample() { |
| 71 | if (isEmpty()) throw new NoSuchElementException(); |
| 72 | int id = (first + StdRandom.uniformInt(n)) % v.length; |
| 73 | return v[id]; |
| 74 | } |
| 75 | |
| 76 | // return an independent iterator over items in random order |
| 77 | public Iterator<Item> iterator() { |