Line | |
---|
1 | function y = diff_rand_ints(ints, n,from,to) |
---|
2 | % Add n ints, randomly chosen between from and to inclusive to the list in ints. |
---|
3 | % The resulting vector of ints should have all different numbers. |
---|
4 | if (to + 1 - from) < n + size(ints,2) |
---|
5 | error(sprintf('Not enough room for %d random numbers from %d to %d', n, from, to)); |
---|
6 | end |
---|
7 | for i = 1:n |
---|
8 | x = random_int(from,to-size(ints,2)); |
---|
9 | oldx = from - 1; |
---|
10 | while oldx < x |
---|
11 | temp = x; |
---|
12 | x = x + sum((oldx < ints) & (ints <= x)); |
---|
13 | oldx = temp; |
---|
14 | end |
---|
15 | ints = [ints,x]; |
---|
16 | end |
---|
17 | y = ints; |
---|
Note: See
TracBrowser
for help on using the repository browser.