package vorlesungen;


public class Stochastik21 {
	
	
	 public static void main(String[] args) {
	        
	        //the intensity lambda
	        double lambda = 0.2;
	        //the number of iterations
	        int n = 1000;
	        //the border of the interval 
	        int T = 100;
	        //the number of random variables (Erneuerungszeitpunkte)
	        int m = 0;
	        
	        for(int i=0;i<n;i++) //loop for the repetitions of the simulation
	        {
	            double sum = 0; //sum of the random variables 
	            
	            while(sum<T)
	            {
	                //generate a random number between 0 and 1
	                double u = java.lang.Math.random(); 
	                
	                //transform u into an exponentially distributed random variable with intensity lambda
	                double t = - Math.log(u)/lambda; 
	                if(sum+t<T)
	                {
	                    sum = sum + t;
	                    m++;
	                    //export of the first realization
	                    if(i==0)
	                        System.out.println("Erneuerungszeitpunkt "+m+": "+sum);
	                }
	                else
	                    break;
	            }
	  
	        }
	        //calculation of the mean intensity 
	        System.out.println("Erwartete Anzahl an Erneuerungspunkten: "+lambda*T);
	        System.out.println("Mittlere Anzahl an Erneuerungspunkten bei "+n+" Iterationen: "+m/(double)n);
	    }
	

}

