Home > mfiles > randInt.m

randInt

PURPOSE ^

randInt - create random integers.

SYNOPSIS ^

function r = randInt(arg,varargin)

DESCRIPTION ^

 randInt - create random integers.

 r = randInt(N);
   returns a random uniformly distributed integer 1 <= r <= N.

 r = randInt([M N]);
   returns a random uniformly distributed integer M <= r <= N.

 r = randInt(M,sz) and r = randInt([M N],sz)
   returns an array of size sz with random integers.

 If sz is a scalar, a square array of size [sz sz] is returned.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % randInt - create random integers.
0002 %
0003 % r = randInt(N);
0004 %   returns a random uniformly distributed integer 1 <= r <= N.
0005 %
0006 % r = randInt([M N]);
0007 %   returns a random uniformly distributed integer M <= r <= N.
0008 %
0009 % r = randInt(M,sz) and r = randInt([M N],sz)
0010 %   returns an array of size sz with random integers.
0011 %
0012 % If sz is a scalar, a square array of size [sz sz] is returned.
0013 
0014 % This file is part of the SaliencyToolbox - Copyright (C) 2006-2007
0015 % by Dirk B. Walther and the California Institute of Technology.
0016 % See the enclosed LICENSE.TXT document for the license agreement.
0017 % More information about this project is available at:
0018 % http://www.saliencytoolbox.net
0019 
0020 function r = randInt(arg,varargin)
0021 
0022 if (isempty(varargin))
0023   sz = 1;
0024 else
0025   sz = varargin{1};
0026 end
0027 
0028 
0029 if (length(arg) < 2)
0030   m = 1;
0031   n = arg(1);
0032 else
0033   m = arg(1);
0034   n = arg(2);
0035 end
0036 
0037 r = floor(rand(sz)*(n-m+1) + m);

Generated on Fri 07-Sep-2007 14:42:18 by m2html © 2003