Mercurial > hg > webaudioevaluationtool
comparison core.js @ 207:32e16bf9303a
Keep track of randomisation in console log; multipage example XML.
author | Brecht De Man <b.deman@qmul.ac.uk> |
---|---|
date | Mon, 15 Jun 2015 16:54:39 +0100 |
parents | 30b9d9538cb7 |
children | 538322113524 |
comparison
equal
deleted
inserted
replaced
206:59eea6eed91b | 207:32e16bf9303a |
---|---|
1067 | 1067 |
1068 function randomiseOrder(input) | 1068 function randomiseOrder(input) |
1069 { | 1069 { |
1070 // This takes an array of information and randomises the order | 1070 // This takes an array of information and randomises the order |
1071 var N = input.length; | 1071 var N = input.length; |
1072 var K = N; | 1072 |
1073 var inputSequence = []; // For safety purposes: keep track of randomisation | |
1074 for (var counter = 0; counter < N; ++counter) | |
1075 inputSequence.push(counter) // Fill array | |
1076 var inputSequenceClone = inputSequence.slice(0); | |
1077 | |
1073 var holdArr = []; | 1078 var holdArr = []; |
1079 var outputSequence = []; | |
1074 for (var n=0; n<N; n++) | 1080 for (var n=0; n<N; n++) |
1075 { | 1081 { |
1076 // First pick a random number | 1082 // First pick a random number |
1077 var r = Math.random(); | 1083 var r = Math.random(); |
1078 // Multiply and floor by the number of elements left | 1084 // Multiply and floor by the number of elements left |
1079 r = Math.floor(r*input.length); | 1085 r = Math.floor(r*input.length); |
1080 // Pick out that element and delete from the array | 1086 // Pick out that element and delete from the array |
1081 holdArr.push(input.splice(r,1)[0]); | 1087 holdArr.push(input.splice(r,1)[0]); |
1088 // Do the same with sequence | |
1089 outputSequence.push(inputSequence.splice(r,1)[0]); | |
1082 } | 1090 } |
1091 console.log(inputSequenceClone.toString()); // print original array to console | |
1092 console.log(outputSequence.toString()); // print randomised array to console | |
1083 return holdArr; | 1093 return holdArr; |
1084 } | 1094 } |
1085 | 1095 |
1086 function returnDateNode() | 1096 function returnDateNode() |
1087 { | 1097 { |