Random elements different positions

You can do this by creating a vector array and every time you create a random x-y value cheque in the array if it doesn’t already exist, meaning not 0. When not, draw the square and save the position in the array.