function startSamp = pickstime(startSamp1, startSamp2, varargin)

% PICKSTIME - pick signal start time from range in samples
%
% startSamp = pickstime(startSamp1, startSamp2)
%   Pick number of start times equal to the length of startSamp1
% startSamp = pickstime(startSamp1, startSamp2, nstime)
%   Pick nstime number of start times
%
% startSamp1    minimum start time in samples
% startSamp2    maximum start time in samples
% nstime        (optional) number of start times to generate
%
% startSamp     determined start time(s) in samples

% $Id: pickstime.m,v 1.2 2004/05/10 20:26:13 stuver Exp $

% DETERMINE number of start times to generate
% DETERMINE interval of start times
% SET start times

startSamp = [];

% Determine number of start times to generate
if length(varargin) == 0
    % If nstime is not input, set it to the number of ranges input
    nstime = size(startSamp1, 1);
elseif length(varargin) == 1
    % If nstime is input, assume that startSamp1 and startSamp2 are scalars 
    % and generate a vector of minimum start times
    nstime = varargin{1};
    startSamp1(1:nstime) = startSamp1;
end

% Determine interval of start times
interval = startSamp2-startSamp1;
% Check interval for error
if interval < 0
    error('makelist -> pickstime: startSamp1 must be < startSamp2')
end

% Set start times
for k=1:nstime
    % Pick a random number in the interval
    samp = rand(1)*interval; % This includes intersample start
    % Add randomly picked sample to startSamp1
    startSamp(k) = startSamp1(k)+samp(k);
end

return