Q:

Random values combined with assignment/combinator operator

Does the following code sample create two random values, or does it re-use the first one?
Random r = new Random();
int[] a = new int[10];

a[r.nextInt(10)] += 1;

// Equals this, creating two random values:
a[r.nextInt(10)] = a[r.nextInt(10)] + 1;

// Or this, using 6 as the result of the first random operation
a[6] = 6 + 1;

Edit: while we're at it, does this operator (and others like -=, /=, etc) have a name?

A:

When you write a[r.nextInt(10)] += 1; there is only one random number generated. So if this random number happens to be 6 this is equivalent to a[6] = a[6] + 1; (but slightly more efficient).

does this operator (and others like -=, /=, etc) have a name?

They are called shortcut assignment operators.

