Mercurial > hg > octave-lyh
changeset 14706:52c5fb67fa5f
maint: periodic merge of stable to default
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 31 May 2012 16:09:57 -0400 |
parents | a08f6e17336e (current diff) b9bbd4c569ba (diff) |
children | b44ae6c1484a 9bd34ddf29fe 3b067a247c1d |
files | .hgtags configure.ac src/DLD-FUNCTIONS/rand.cc |
diffstat | 2 files changed, 17 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgtags +++ b/.hgtags @@ -66,3 +66,4 @@ 704f7895eef03008dd79848eb9da4bfb40787d73 release-3-6-0 f947d2922febf12dcd1fb6e21b356756ecb54e55 rc-3-6-2-0 4460c4fb20e6a5d3b1972fa737d4e00eb921545a rc-3-6-2-2 +551566201318bf615b27c60ccf9368f4844008bd release-3-6-2
--- a/src/DLD-FUNCTIONS/rand.cc +++ b/src/DLD-FUNCTIONS/rand.cc @@ -1164,14 +1164,19 @@ octave_idx_type k = i + gnulib::floor (rvec[i] * (n - i)); - if (map.find(k) == map.end()) + //For shuffling first m entries, no need to use extra + //storage + if (k < m) { - map[k] = ivec[i]; - ivec[i] = k; + std::swap (ivec[i], ivec[k]); } else - std::swap (ivec[i], map[k]); + { + if (map.find (k) == map.end ()) + map[k] = k; + std::swap (ivec[i], map[k]); + } } } else @@ -1206,4 +1211,11 @@ /* %!assert (sort (randperm (20)), 1:20) %!assert (length (randperm (20,10)), 10) + +%!test +%! rand ("seed", 0); +%! for i = 1:100 +%! p = randperm (305, 30); +%! assert (length (unique (p)), 30); +%! endfor */