function [A u] = place_N_queens_random(N) % this function places N queens on random places % on the NxN board, and returns an NxN matrix with N queens A = zeros(N); u = 0; % current number of queens in the matrix while u ~= N p=randperm(N); p=p(1); q=randperm(N); q=q(1); A(p, q) = 1; u = numel(find(A)); end end