File: Ranint.m

package info (click to toggle)
psychtoolbox-3 3.0.19.14.dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 86,796 kB
  • sloc: ansic: 176,245; cpp: 20,103; objc: 5,393; sh: 2,753; python: 1,397; php: 384; makefile: 193; java: 113
file content (24 lines) | stat: -rw-r--r-- 611 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
function i = Ranint(dim,n)
% i = Ranint([dim],n)
%
% Choose "dim" random integers in the range 1:n.
%
% For historical reasons, the usage is a little weird.  If you omit the dim
% argument, then a single random integer is drawn from the range 1:n. 
% 
% Also see Randi.

% 4/10/94   dhb   Added optional first argument.
% 8/19/94   dhb   Clarified comment.
% 1/20/97   dhb   Delete obsolete rand('uniform').
% 4/12/99   dgp   Changed names of arguments to be consistent with Matlab and Randi.
% 7/24/04   awi   Cosmetic.

if nargin == 1
	n = dim;
	dim = 1;
end

list = rand(dim,1);
i = floor( n .* list ) + 1;