diff core.js @ 774:67c6048d920f

Specification: sync across project. Now randomises audioElements.
author Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk>
date Mon, 07 Dec 2015 18:34:26 +0000
parents d07bc42a716c
children bb02c801c8c9
line wrap: on
line diff
--- a/core.js	Mon Dec 07 18:26:12 2015 +0000
+++ b/core.js	Mon Dec 07 18:34:26 2015 +0000
@@ -1398,6 +1398,34 @@
 			}
 		};
 	};
+	
+	this.randomiseOrder = function(input)
+	{
+		// This takes an array of information and randomises the order
+		var N = input.length;
+		
+		var inputSequence = []; // For safety purposes: keep track of randomisation
+		for (var counter = 0; counter < N; ++counter) 
+			inputSequence.push(counter) // Fill array
+		var inputSequenceClone = inputSequence.slice(0);
+		
+		var holdArr = [];
+		var outputSequence = [];
+		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]);
+			// Do the same with sequence
+			outputSequence.push(inputSequence.splice(r,1)[0]);
+		}
+		console.log(inputSequenceClone.toString()); // print original array to console
+		console.log(outputSequence.toString()); 	// print randomised array to console
+		return holdArr;
+	};
 	this.projectReturn = null;
 	this.randomiseOrder = null;
 	this.collectMetrics = null;
@@ -1810,6 +1838,11 @@
 				}
 			}
 			
+			if (this.randomiseOrder == true)
+			{
+				this.audioElements = randomiseOrder(this.audioElements);
+			}
+			
 			var commentQuestionsDOM = xml.getElementsByTagName('CommentQuestion');
 			for (var i=0; i<commentQuestionsDOM.length; i++) {
 				var node = new this.commentQuestionNode();