What you want, then, is a random shuffle of certain elements.
Keepee's solution would work however he is right in the fact that it is not the most efficient solution.
What I think you might need to do is fill out a 1-dimensional array beforehand, either manually or procedurally, then shuffle it.
Shuffling the array is not simple, but here's a nice example of it being done.
I might have missed a better way of doing it, but I think this will work if done right.