diff test_create/test_create.html @ 380:42cf69a134aa Dev_main

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 6139c53deba1
children 17a2b99622c0
line wrap: on
line diff
--- a/test_create/test_create.html	Mon Dec 07 18:26:12 2015 +0000
+++ b/test_create/test_create.html	Mon Dec 07 18:34:26 2015 +0000
@@ -1617,6 +1617,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;
@@ -2029,6 +2057,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();
@@ -2283,7 +2316,7 @@
 					};
 				};
 			}
-			
+		
 			function createDeleteNodeButton(node)
 			{
 				var button = document.createElement("button");