//  ------------------------------------------------------
//  -------  Aufgabe 4.20 4.)    Ib03     ----------------
//  -------                               ----------------
//  -------  Zufallszahlen-Generator      ----------------
//  -------  exponentiel verteilt         ----------------
//  -------                               ----------------
//  -------  25.06.2005    M. Vogel       ----------------
//  ------------------------------------------------------

public class Uebung4_20_4
{
	final static int M = 1000000 ;  // Anzahl Simulationen
	static double lambda;  // Exp. Parameter
	
	public static void main(String[] args){
	System.out.println() ;
	InOut.print("Bitte Parameter lambda der Exp-Verteilung eingeben : "); 
	lambda = InOut.getDouble();
	
	double sum1 =0;
	double sum2 =0;
	double x;
	int count =0;
		
      for (int n = 0; n<M; n++)
	  {
	    x = zufall();
		sum1 +=x;
		sum2 +=x*x;
		
    	  count++;
		  if(count <= 25) System.out.println("Zufallszahl " + count + "   : "+ x ) ;
	  }	

	  double ex = sum1/M ;
	  double sigma = Math.sqrt(sum2/M - ex*ex); 
	  System.out.println() ;
	  System.out.println("Erwartungswert :     simuliert = " + ex    + "          theoretisch = " + 1.0/lambda) ;
	  System.out.println("Standardabweichung : simuliert = " + sigma + "          theoretisch = " + 1.0/lambda) ;
			
	}
	
	static double zufall(){
	 	return -Math.log( 1.0 - Math.random() )/lambda ;  //  
	}
}

