Skip to content

Instantly share code, notes, and snippets.

@dasniko
Created April 5, 2013 05:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dasniko/5316963 to your computer and use it in GitHub Desktop.
Save dasniko/5316963 to your computer and use it in GitHub Desktop.
package jug.da.lottery;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class Lottery {
public static void main(String[] args) {
Lottery lottery = new Lottery();
lottery.start();
}
public void start() {
List<String> participants = getParticipants();
System.out.println("Participant count: " + participants.size());
Random r = new Random();
int idx = r.nextInt(participants.size());
System.out.println("Winner: " + participants.get(idx));
}
private List<String> getParticipants() {
List<String> p = new ArrayList<String>();
try {
@SuppressWarnings("resource")
BufferedReader in = new BufferedReader(new FileReader(
"c:\\temp\\participants.txt"));
String line = "";
while ((line = in.readLine()) != null) {
p.add(line);
}
} catch (IOException e) {
e.printStackTrace();
}
return p;
}
}
@hameister
Copy link

Ok, ein GitHub-Projekt wäre übertrieben gewesen... :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment