This is what actually happens in the Windows original (it doesn't look for a random empty square, it tries them in reading order starting from the top left).
Well you have all the cells in an array so that's easy enough. Pick a cell at random until you find an empty one, which won't take long. There's no regeneration, just moving one mine to an easy to find place.