function Entropy() {
	this.data = [];
	this.readIndex = 0;
	this.lastMouseX = 0;
	this.lastMouseY = 0;
	this.lastTimeEvent = 0;
	this.maxSize = 1024;
	this.minSize = 128;
	
	this.minMouseDistance = 50;
	
	this.addByte = function(b) {
		this.data.push(b);
		if (this.data.length > this.maxSize)
			this.data.shift();
	}
	
	this.clear = function() {
		this.data.length = 0;
		this.readIndex = 0;
	}
	
	this.fillFactor = function() {
		return this.getNumBytes() / this.minSize ;
	}
	
	this.isReady = function() {
		if (this.fillFactor() >= 1)
			return true;
		return false;
	}
	
	this.readByte = function() {
		var b = 0;
		
		if (this.data.length > 0) {			
			if (this.readIndex >= this.data.length) {
				this.readIndex = 0;
			}		
			b = this.data[this.readIndex];
			this.readIndex++;
		}
		
		return b;
	}
		
	this.addTimeEvent = function() {
		var t = new Date();
		if (t > (this.lastTimeEvent+1000)) {
			this.addByte(t % 256);
			this.lastTimeEvent = t;
			return true;
		}
		return false;
	}

	this.getNumBytes = function() {
		return this.data.length;
	}	
	
	this.getNumBits = function() {
		return this.data.length * 8;
	}
		
	this.addMouseEvent = function(e) {
	
		function mouseX(evt) {			
			if ((evt.pageX!=undefined)&&(evt.pageX!=null)) return evt.pageX;
			else if ((evt.clientX!=undefined)&&(evt.clientX!=null))
			   return evt.clientX + (document.documentElement.scrollLeft ?
			   document.documentElement.scrollLeft :
			   document.body.scrollLeft);
			else return null;
		}
		
		function mouseY(evt) {
			if ((evt.pageY!=undefined)&&(evt.pageY!=null)) return evt.pageY;
			else if ((evt.clientY!=undefined)&&(evt.clientY!=null))
			   return evt.clientY + (document.documentElement.scrollTop ?
			   document.documentElement.scrollTop :
			   document.body.scrollTop);
			else return null;
		}	

		var t = new Date();
		var x = mouseX(e);
		var y = mouseY(e);
		
		if ((x > 0) && (y > 0) && (t > 0)) {
			var dx = (x - this.lastMouseX);
			var dy = (y - this.lastMouseY);
			var r = Math.sqrt(dx*dx+dy*dy);
			if (r > this.minMouseDistance) {
				var b = ((x%16)*16+(y%16)) ^ (t % 256);
				this.addByte(b);
				this.lastMouseX = x;
				this.lastMouseY = y;
				return true;
			}
		}
		
		return false;			
	}
}


