ArrayList
Random
and KeysThe Random
class is a “psuedo-random number generator” (PRNG)
long key = 2685452;
Random r = new Random(key); // use key for Random seed
r.nextInt(10); // a 'random' # from 0 to 9
r.nextInt(10); // another 'random' # from 0 to 9
r.nextInt(10); // another 'random' # from 0 to 9
Random
objects will produce the same sequence of numberskey
$\implies$ new Random(key)
$\implies$ substitution table
What we want:
Random
?How do we represent a “deck of cards”?
ArrayList
, Part IArrayList<type>
is a Javaimport java.util.ArrayList
to useArrayList
storing int
s:ArrayList<Integer> al = new ArrayList<Integer>();
al.add(1);
al.add(2);
al.add(3);
ArrayList
, Part IIArrayList
ai.size(); // returns 3
ArrayList
ai.get(0); // returns 1
ai.get(1); // returns 2
ai.get(2); // returns 3
ArrayList
ai.remove(1); // returns 2, ArrayList now stores [1, 3]
ai.size(); // now returns 2 (new size after removal)