@Override
	public synchronized void run() {
		try{ 
			while (true){
				while (ch1.isEmpty()||!ch2.isEmpty()){ 
					wait(); 
				} // Wait for something to do
				val=int_receive();
				while (numberOfRepetitionAndLost < maxError){
					Random random = new Random();
					int randomInt = random.nextInt(3);	// randomInt gets the values 0, 1 and 2 which 
					int safeInt = 0;
					// correspond to losing, duplicating or properly sending messages		
					switch (safeInt) {
					case 0: // Send normally
						int_send(val);
						numberOfRepetitionAndLost= maxError; //now, you will not continue in while-loop
						break;
					case 1: // Lose the message, i.e, the message is not delivered
						numberOfRepetitionAndLost++;
						break;
					case 2: // Duplicate the message
						int_send(val);
						numberOfRepetitionAndLost++;
						break;
					}
					while (!ch2.isEmpty()){ 
						wait();
					} // if message is sent, wait for receiver before looping
				}
				numberOfRepetitionAndLost = 0; // reset for next message
			}
		} catch (Exception e){}
	}