Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
% function y = randintexc(N,M,exclus,varargin)
% returns N random integers between 1 and M exclussively
% also excludes values in array exclus
function y = randintexc(N,M,exclus,varargin)
if N > M
disp('Error: Too many numbers')
y = -1;
return
end
if nargin == 3
if N > M - length(exclus)
disp('Error: Too many numbers')
y = -1;
return
end
end
r(1) = ceil(M*rand);
for nloop = 2:N
testflag = 0;
while testflag == 0
temp = ceil(M*rand);
flag = 0;
for cntloop = 1:nloop-1
if temp == r(cntloop)
flag = 1;
end
end
if nargin == 3
for loop = 1:length(exclus)
if temp == exclus(loop)
flag = 1;
end
end
end
if flag == 0
r(nloop) = temp;
testflag = 1;
end
end % end while
end
y = r;