public static void repair(Random rand, int[][] square, int n)
    {
        HashSet<Integer> found = new HashSet<Integer>();
        
        LinkedList<Duplicate> dups = new LinkedList<Duplicate>();
        
        for(int i=0; i<n; i++)
        {
            for(int j=0; j<n; j++)
            {
                if(!found.add(square[i][j]))
                {
                    dups.add(new Duplicate(square[i][j], i, j));
                }
            }
        }
        
        ArrayList<Integer> missing = new ArrayList<Integer>();
        
        for(int i=1; i<=n*n; i++)
        {
            if(!found.contains(i))
            {
                missing.add(i);
            }
        }
        
        for(Duplicate dup : dups)
        {
            int missingIndex         = rand.nextInt(missing.size());
            square[dup.row][dup.col] = missing.get(missingIndex);
            
            missing.remove(missingIndex);
        }
    }