/*


auteur			:	Sjoerd

datum			:	31/01/2009

beschrijving	:	Een javascript object dat een lijst getallen in het interval [lowerBound_in,upperBound_in] De methode nextRandom() geeft iedere keer één random getal uit de lijst terug. Dit wordt dan uit de lijst verwijderd. Als het laatste getal uit de lijst wordt gehaald wordt de lijst opnieuw gevuld. 
voorbeeld		: zie random_zonder_teruglegging_voorbeeld.html

*/


//define object
function random_zonder_teruglegging(lowerBound_in,upperBound_in){
	this.lowerBound = lowerBound_in;
	this.upperBound = upperBound_in;
	this.randomCollection = new Array()
	this.fill();
}

//define methods for random_zonder_teruglegging
random_zonder_teruglegging.prototype.nextRand = function() {
	if(this.randomCollection.length > 1)
	{
		return (this.randomCollection.pop());
	}
	else
	{
		lastValue = this.randomCollection.pop()
		this.fill();
		return(lastValue);
	}
		
}

random_zonder_teruglegging.prototype.fill = function(){
//initialise randomcollection as array containing integers from lowerBound to upperBound, including the bounds themselves
	var i = this.lowerBound;
	while (i <= this.upperBound) 
	{
	   
	   this.randomCollection.push(i);
	   i = i+1;
	}
	//randomize the array
	this.randomCollection = this.randomCollection.sort(randOrd);
}
random_zonder_teruglegging.prototype.toString = function(){
	return("collection: "+ this.randomCollection);
}

//hulp functies
function randOrd(){
	return (Math.round(Math.random())-0.5); 
} 
