diff options
author | charlescharles <charlescharles@users.noreply.github.com> | 2014-10-28 23:17:58 +0300 |
---|---|---|
committer | charlescharles <charlescharles@users.noreply.github.com> | 2014-10-28 23:54:01 +0300 |
commit | 2c4bac0c89168e0e517241402e4cfdb41f7d2ef5 (patch) | |
tree | 01db8245bbafbda7c8d81d44d20a2fb01bd648ec /lib/torrent.js | |
parent | b6a970372be69d349750073cdee7c3549eee9016 (diff) |
Fix Knuth shuffle
Diffstat (limited to 'lib/torrent.js')
-rw-r--r-- | lib/torrent.js | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/torrent.js b/lib/torrent.js index c55cebc..7659314 100644 --- a/lib/torrent.js +++ b/lib/torrent.js @@ -986,8 +986,8 @@ function randomInt (high) { function randomizedForEach (array, cb) { var indices = array.map(function (value, index) { return index }) - for (var i = 0, len = indices.length; i < len; ++i) { - var j = randomInt(len) + for (var i = indices.length - 1; i > 0; --i) { + var j = randomInt(i + 1) var tmp = indices[i] indices[i] = indices[j] indices[j] = tmp |