forked from pdollar/toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
randint2.m
34 lines (33 loc) · 968 Bytes
/
randint2.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
function R = randint2( m, n, range )
% Faster but restricted version of randint.
%
% Generate matrix of uniformly distributed random integers.
% R=randint2(m,n,range) generates an m-by-n matrix of random integers
% between [range(1), range(2)]. Note that randint is part of the
% 'Communications Toolbox' and may not be available on all systems.
%
% To test speed:
% tic, for i=1:1000; R = randint( 100, 10, [0 10] ); end; toc
% tic, for i=1:1000; R = randint2( 100, 10, [0 10] ); end; toc
%
% USAGE
% R = randint2( m, n, range )
%
% INPUTS
% m - m rows
% n - n cols
% range - range of ints
%
% OUTPUTS
% R - mxn matrix of integers
%
% EXAMPLE
% R = randint2( 2, 5, [0 1] )
%
% See also RANDINT
%
% Piotr's Computer Vision Matlab Toolbox Version 2.12
% Copyright 2014 Piotr Dollar. [pdollar-at-gmail.com]
% Licensed under the Simplified BSD License [see external/bsd.txt]
R = rand( m, n );
R = range(1) + floor( (range(2)-range(1)+1)*R );