import java.util.Random;


public class SeveralThreadsA implements Runnable {

	int myID;
	Random gen;
	
	public SeveralThreadsA (int num) {
		myID = num;
		gen = new Random();
	}
		@Override
	public void run() {
		for (int i=0; i<5; i++) {
			try {
				int sleepyNoise = gen.nextInt(200) - 100;
				Thread.sleep(200 + sleepyNoise);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				System.out.println("exception caught");
			}
	
			System.out.println("   thread: " + myID + "\tloop#: " + i);
		}
	}
	
	public static void main(String[] args) {
		for (int i=1; i<3; i++) {
		(new Thread (new SeveralThreadsA(i))).start();
		}
		
		for (int i=0; i<4; i++) {
			try {
				Thread.sleep(300);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			System.out.println("main " + i);
			}
	}
}
	
