function [c,d,x,n]=cdeal(d)
% cdeal <Deal a deck of cards.>
% Usage:: [c,d,x,n]=cdeal(d)
%

% revision history:
% 01/08/13 Mark D. Shattuck <mds> cdeal.m

%% Main

N=52;
SS='CDHS';
CC='A23456789TJQK';

if (~exist('d','var') || isempty(d))
  d=0:N-1;
end

Nc=length(d);

n=fix(Nc*rand);
x=d(n+1);

c=[CC(rem(x,13)+1) SS(fix(x/13)+1)];

d=d([1:n n+2:end]);
save d d;
