Mercurial > hg > webaudioevaluationtool
changeset 1664:bf302b83c58e
Added in randomiseOrder function in core.js. Updated calls in ape.js to randomise order of tests and elements.
author | Nicholas Jillings <nickjillings@users.noreply.github.com> |
---|---|
date | Fri, 17 Apr 2015 09:41:31 +0100 |
parents | e51d1aa4e7e5 |
children | 6d000b353a7e |
files | ape.js core.js |
diffstat | 2 files changed, 20 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/ape.js Mon Apr 13 11:46:21 2015 +0100 +++ b/ape.js Fri Apr 17 09:41:31 2015 +0100 @@ -59,7 +59,7 @@ } if (randomise) { - // TODO: Implement Randomisation!! + testXMLSetups = randomiseOrder(testXMLSetups); } // Obtain the metrics enabled @@ -341,7 +341,7 @@ currentTrackOrder[index] = element; }); if (randomise) { - // TODO: Randomise order + currentTrackOrder = randomiseOrder(currentTrackOrder); } // Find all the audioElements from the audioHolder
--- a/core.js Mon Apr 13 11:46:21 2015 +0100 +++ b/core.js Fri Apr 17 09:41:31 2015 +0100 @@ -340,4 +340,22 @@ this.listenStart = 0; } }; +} + +function randomiseOrder(input) +{ + // This takes an array of information and randomises the order + var N = input.length; + var K = N; + var holdArr = []; + for (var n=0; n<N; n++) + { + // First pick a random number + var r = Math.random(); + // Multiply and floor by the number of elements left + r = Math.floor(r*input.length); + // Pick out that element and delete from the array + holdArr.push(input.splice(r,1)[0]); + } + return holdArr; } \ No newline at end of file