* Shuffles data and target (maintaining alignment) using Fisher-Yates * algorithm.flab
(data, target)
| 108 | * algorithm.flab |
| 109 | */ |
| 110 | function shuffle(data, target) { |
| 111 | let counter = data.length; |
| 112 | let temp = 0; |
| 113 | let index = 0; |
| 114 | while (counter > 0) { |
| 115 | index = (Math.random() * counter) | 0; |
| 116 | counter--; |
| 117 | // data: |
| 118 | temp = data[counter]; |
| 119 | data[counter] = data[index]; |
| 120 | data[index] = temp; |
| 121 | // target: |
| 122 | temp = target[counter]; |
| 123 | target[counter] = target[index]; |
| 124 | target[index] = temp; |
| 125 | } |
| 126 | }; |