root/matlab/randindex.m

Revision 407, 443 bytes (checked in by tapted, 4 years ago)

Import of some matlab code written during honours

Line 
1function idxs = randindex(asize)
2  % Returns an array of random indirect indexes for an array of size asize
3  %
4  % Author: Trent Apted / tapted / 0010433
5
6  for i=1:asize,
7      idxs(i) = i;
8  end
9  for i=1:asize,
10      x=randBetween(i, asize);
11      tmp=idxs(i);
12      idxs(i) = idxs(x);
13      idxs(x) = tmp;
14  end
15     
16
17function idx = randBetween(m, n)
18  r = rand(1);
19  if r == 1.0
20      r = 1.0 - eps;
21  end
22  idx = floor(r*(n-m+1)) + m;
Note: See TracBrowser for help on using the browser.