File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1237,12 +1237,23 @@ function generateTrainCaseList() {
12371237 if ( trainCaseListTemp . length == 0 ) ELEM_SCRAMBLE . innerHTML = "no case selected" ;
12381238
12391239 // Randomize Cases
1240- trainCaseListTemp . sort ( ( ) => Math . random ( ) - 0.5 ) ;
1240+ shuffleArray ( trainCaseListTemp ) ;
12411241
12421242 // Add new cases to current list
12431243 trainCaseList = trainCaseList . concat ( trainCaseListTemp ) ;
12441244}
12451245
1246+ /**
1247+ * https://stackoverflow.com/a/12646864
1248+ * Less biased shuffle
1249+ */
1250+ function shuffleArray ( array ) {
1251+ for ( let i = array . length - 1 ; i > 0 ; i -- ) {
1252+ const j = Math . floor ( Math . random ( ) * ( i + 1 ) ) ;
1253+ [ array [ i ] , array [ j ] ] = [ array [ j ] , array [ i ] ] ;
1254+ }
1255+ }
1256+
12461257/**
12471258 * Show next/previous case
12481259 * Called when user clicks on Previous/Next Scramble button or presses space
You can’t perform that action at this time.
0 commit comments