import java.util.*;
import java.io.*;

/**
 @author    <A HREF="http://www.thur.de/~Voland/">René Scholz</A>.
 @version   1.0

 USE: Program to calculate the winners of a raffle.

**/


public class raffle {
  public static void main (String[] args) {

    try {

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    System.out.print("Zufaelligen Startwert eingeben: ");
    int seed = Integer.parseInt(br.readLine());

    System.out.print("Anzahl aller Bewerber: ");
    int COUNT_BEWERBER = Integer.parseInt(br.readLine());

    System.out.print("Anzahl zu berechnender Zufallszahlen: ");
    int COUNT_ZUFALL = Integer.parseInt(br.readLine());

    System.out.println("");
    
    if(COUNT_ZUFALL >= COUNT_BEWERBER) {
      System.out.println("Alle Bewerber haben gewonnen!");
      System.exit(0);
    }
    
    
    /** Array which holds the numbers of all competitors. */
    int ALL[] = new int[COUNT_BEWERBER];
    for(int i=0; i<ALL.length; i++) ALL[i]=i; // put competitors into the array
    
    
    /** Array which holds the winner numbers. */
    int GEWINNER[] = new int[COUNT_ZUFALL];

    /** Select _random_ seed value, for instance from here:
	http://www.staatliche-lotterieverwaltung.de/gewinne/gwz-as.asp
     */
    Random R = new Random(seed);
    
    int z;
    int last = ALL.length;
    int c    = COUNT_ZUFALL;
    int done = 0;

    // here we do the raffle:
    while(c-->0) {
      z = R.nextInt(last--);
      System.out.println("wuerfle: " + z + " --> " + ALL[z]);
      GEWINNER[done++] = ALL[z];
      ALL[z] = ALL[last];
    }


    System.out.println("\nGewinner: ");
    for(int i=0; i<GEWINNER.length; i++)
      System.out.print(GEWINNER[i] + " ");
    System.out.println("");
    

    }
    catch (IOException e) {
      System.out.println("IO-Fehler: " + e + "\nProgramm wird beendet!");
      System.exit(-1);
    }
    
  }
}