# Differences

This shows you the differences between two versions of the page.

 algorithm:fisher-yates_shuffle [2012/10/02 22:24]will algorithm:fisher-yates_shuffle [2015/02/02 08:28] (current) Both sides previous revision Previous revision 2015/01/29 23:00 will Title.2015/01/29 09:26 will 2014/07/05 22:40 will 2014/06/25 23:21 will 2014/05/04 16:25 external edit2013/05/04 15:58 will 2013/04/29 09:53 will 2013/04/22 20:00 will 2013/04/22 19:58 will 2013/04/22 19:57 will 2013/04/22 19:54 will 2013/04/22 19:53 will 2013/04/22 19:52 will 2013/04/20 22:38 will 2013/04/20 22:38 will 2013/04/20 22:37 will 2013/04/20 22:37 will 2013/04/20 22:36 will 2013/04/20 22:33 will 2012/10/04 21:59 external edit2012/10/02 22:24 will 2012/09/03 11:31 will 2012/08/31 22:00 will created Next revision Previous revision 2015/01/29 23:00 will Title.2015/01/29 09:26 will 2014/07/05 22:40 will 2014/06/25 23:21 will 2014/05/04 16:25 external edit2013/05/04 15:58 will 2013/04/29 09:53 will 2013/04/22 20:00 will 2013/04/22 19:58 will 2013/04/22 19:57 will 2013/04/22 19:54 will 2013/04/22 19:53 will 2013/04/22 19:52 will 2013/04/20 22:38 will 2013/04/20 22:38 will 2013/04/20 22:37 will 2013/04/20 22:37 will 2013/04/20 22:36 will 2013/04/20 22:33 will 2012/10/04 21:59 external edit2012/10/02 22:24 will 2012/09/03 11:31 will 2012/08/31 22:00 will created Line 1: Line 1: - [algorithm ​Fisher-Yates shuffle] + ======= λ Fisher-Yates shuffle ​====== - ====== Algorithm ====== + <​nowiki>​ + ======= Algorithm ​======= function shuffle(a) { function shuffle(a) { for (var i=a.length-1;​ i>0; i--) { for (var i=a.length-1;​ i>0; i--) { - var j = Math.floor(Math.random()*(i+1)); ​// j random integer [0-i] + ​// j is a random integer [0-i] + ​var j = Math.floor(Math.random()*(i+1));​ swap(a, j, i); swap(a, j, i); } } Line 12: Line 14: ​ - ====== Support ====== + ======= Support ​======= function swap(a, i, j) { function swap(a, i, j) { var t = a[i]; a[i] = a[j]; a[j] = t; var t = a[i]; a[i] = a[j]; a[j] = t; } } - a = [1,​2,​3,​4,​5,​6,​7,​8,​9,​0];​ + function run(a) { - function run() { + return shuffle(a); return shuffle(a); } } ​ - ====== Visualisation ====== + ======= Tests ======= + + ​ + + ======= Options ======= + + { + "​title":"​Fisher-Yates shuffle",​ + "​height":"​270px"​ + } + ​ + + ======= Visualisation ​======= <​html>​ <​html>​ - ​<​head>​ + <​head>​ -