Skip to content

Instantly share code, notes, and snippets.

@chenshuo
Created April 29, 2011 12:07
Show Gist options
  • Save chenshuo/948216 to your computer and use it in GitHub Desktop.
Save chenshuo/948216 to your computer and use it in GitHub Desktop.
prob of 10 in a row, picking 60 out of 228.
public class Main {
public final static int kHoles = 228;
public final static int kBalls = 60;
public static void main(String[] args) {
Random r = new Random();
int[] hist = new int[kBalls + 1];
for (int round = 0; round < 1000*1000*10; ++round) {
boolean[] holes = new boolean[kHoles+1];
int balls = 0;
while (balls < kBalls) {
int x = r.nextInt(kHoles);
if (!holes[x]) {
holes[x] = true;
++balls;
}
}
int maxContinues = 0;
int continues = 0;
for (int i = 0; i < holes.length; ++i) {
if (holes[i]) {
++continues;
}
else {
if (continues > maxContinues)
maxContinues = continues;
continues = 0;
}
}
++hist[maxContinues];
}
for (int i = 0; i < hist.length; ++i) {
System.out.printf("%2d %d\n", i, hist[i]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment