returnUniqueRan()

This method was written in an effort to display promos in a random order across a page without displaying the same one two or more times.

qArray = new Array('zero','one','two','three','four','five','six','seven','eight','nine'); // this would be your array of things you dont want repeated
usedArray = new Array();

for(i=0;i<qArray.length;i++) {
	document.write(qArray[returnUniqueRan()]);
}

function returnUniqueRan() {	
	unique=0;
	do {
		ran = Math.round(Math.random()*(qArray.length-1));
		mUsed = usedArray.toString();
		if(mUsed.indexOf(ran)==-1) { 
			unique=1
			usedArray[usedArray.length] = ran;
		}
	} while (!unique);
	return ran;
	
}


slayer.office home