Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 88b5454

Browse files
committed
Fixed fisheryates algorithm
1 parent 51228e0 commit 88b5454

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/shuffle/fisheryates.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
var size = array.length;
2222
var rand;
2323
var temp;
24-
for (var i = 1; i < size; i += 1) {
25-
rand = Math.round(Math.random() * i);
24+
for (var i = 0; i < size; i += 1) {
25+
rand = Math.floor(i + Math.random() * (size - i));
2626
temp = array[rand];
2727
array[rand] = array[i];
2828
array[i] = temp;

0 commit comments

Comments
 (0)