function  chev = make_chev(N_trials)

%MAKE_CHEV -- Generate a "chance event" matrix for use with PLMODEL1.
%
%  chev = make_chev(N_trials)
%  chev = make_chev(N_trials)
%
%  CHEV is a "chance event matrix" suitable for passing to PLMODEL1, etc.
%  N_TRIALS specifies the number of rows in CHEV.
%  The result CHEV is an N_TRIALS-by-2 matrix of integer "entry points"
%  suitable for passing to the function RANDOM_TABLE.
%
%  See also RAND, RANDOM_TABLE, PLMODEL1.

%  Original coding by Alexander Petrov, UC Irvine.
%  $Revision: 1.0 $  $Date: 2002/07/28 13:01 $

%-- Assume the length of the global NRANDOM_TABLE is 999983.
% No access to the actual variable is attempted. It is highly advisable
% that this is some large prime number. 999983 was chosen as being the
% largest prime less than one million.
NRANDOM_TABLE_length = 999983 ;
max_step = round(sqrt(NRANDOM_TABLE_length)) ;         % 1000 for 999983

%-- Generate two integer "entry points" per trial (see fun RANDOM_TABLE)
chev = rand(N_trials,2) ;
chev(:,1) = ceil(chev(:,1) .* NRANDOM_TABLE_length) ;  % starting index
step = round(chev(:,2) .* (2*max_step)) - max_step ;   % -1000<step<+1000
step(find(step==0)) = 1 ;    % avoid zero steps
chev(:,2) = step ;

%--- Return CHEV
%%%%% End of file MAKE_CHEV.M
