totalCells
and the number of remaining zeros remainingZeros
.flip
:
a. Generate a random index randIndex
from 0 to remainingZeros - 1
.
b. If randIndex
is not in the HashMap, use it as the matrix index. Otherwise, use the value from the HashMap.
c. Swap the value at randIndex
with the value at remainingZeros - 1
in the HashMap.
d. Decrease remainingZeros
by 1.
e. Return the matrix indices corresponding to randIndex
.reset
:
a. Clear the HashMap.
b. Reset remainingZeros
to totalCells
.