-
Notifications
You must be signed in to change notification settings - Fork 2
/
get_rand.m
43 lines (36 loc) · 921 Bytes
/
get_rand.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
35
36
37
38
39
40
41
42
43
function r = get_rand(N, M, seed)
% r = get_rand(N, M, seed)
%
% DESC:
% returns a logical vector of length M with N trues uniformly ditributed
%
% AUTHOR
% Marco Zuliani - [email protected]
%
% VERSION
% 1.0.1
%
% INPUT:
% N = number of ones
% M = number of elements
% seed = seed of the random number generator
%
% OUTPUT:
% r = M-dimensional vector with N ones and M-N zeros
%
% HISTORY
% 1.0.0 - ??/??/04 - Initial version
% 1.0.1 - ??/??/06 - Uses logical indexing
% 1.0.2 - 06/25/08 - Fixes the seed of the random number generator
% fix the seed of the random number generator
if (nargin == 3) && ~isempty(seed)
rand('twister', seed);
end;
if (N > M)
error('RANSACToolbox:get_rand', 'N should be less or equal than M');
end;
r = [true(1, N) false(1, M-N+1)];
temp = rand(1, M);
[dummy ind] = sort(temp);
r = r(ind);
return