//  ------------------------------------------------------
//  -------  Prüfung 4.4      Ib03        ----------------
//  -------                               ----------------
//  -------  Bitsumme in Zufallszahlen    ----------------
//  -------                               ----------------
//  -------  31.03.2005    M. Vogel       ----------------
//  ------------------------------------------------------

public class Pruefung4_4
{
	final static int M = 100000 ;  // Anzahl Simulationen
	final static int N =  32    ;  // Bitstring-Laenge
	
	public static void main(String[] args){
	int[] bit   = new int[N]   ;
	int[] score = new int[N+1] ;
		
      for (int n = 0; n<M; n++)
	  {
	    for (int i = 0; i < bit.length ; i++) bit[i]=zufall(); // Generieren von Zufalls-Bitstring
		
		int sum=0 ;	
		for (int i = 0; i < bit.length; i++) sum=sum+bit[i]  ; // Anzahl Einsen im Bitstring

		score[sum]++ ;  // Abfuellen der Z-Verteilung
	  }	
	  
	  for (int j = 0; j <= bit.length; j++) System.out.println(j + " -> " + 100.0*score[j]/M +"%" )  ;

      double sum=0.0 ;
	  for (int j = 18; j <= bit.length; j++) sum=sum+score[j] ;
	  System.out.println() ;
	  System.out.println("P[Z>=18] =" + sum/M ) ;
			
	}
	
	static int zufall(){
	 	return (int)( 0.5+Math.random() );
	}
}

