Try selecting something like this:
import numpy as np
N = 100
m = np.zeros((N, N))
# initial point to start random fill
i, j = np.random.randint(0, N, 2)
# mark as filled
m[i, j] = 1
active = [(i, j)] # add initial to active cells to expand from
while active:
c = np.random.randint(0, len(active)) # choose random cell
i, j = active[c] # get coordinates
# get all neighbors
neighbors = set([(min(N-1, max(0, x)), min(N-1, max(0, y))) for x in range(i-1, i+2) for y in range(j-1, j+2)])
neighbors = [n for n in neighbors if m[n] == 0] # get all unmarked neighbors
if neighbors:
# choose random neighbor and mark it
random_neighbor = neighbors[np.random.randint(0, len(neighbors))]
m[random_neighbor] = 1
if len(neighbors) <= 1: # if there are no more unmarked neighbors left
del active[c] # remove from active list
active.append(random_neighbor) # add marked neighbor to active list
else:
del active[c]