2import umontreal.ssj.probdist.PoissonDist;
3import umontreal.ssj.rng.*;
4import umontreal.ssj.stat.*;
5import umontreal.ssj.util.Chrono;
7public class Collision {
16 public Collision (
int k,
int m,
int maxCounts) {
19 lambda = (double) m * m / (2.0 * k);
20 used =
new boolean[k];
21 this.maxCounts = maxCounts;
22 counts =
new int[maxCounts + 1];
29 for (
int i = 0; i < k; i++) used[i] =
false;
30 for (
int j = 0; j < m; j++) {
31 int loc = stream.nextInt (0, k-1);
33 else used[loc] =
true;
42 for (
int c = 0; c < maxCounts; c++)
44 for (
int i = 0; i < n; i++) {
53 public static void main (String[] args) {
54 int k = 10000;
int m = 500;
57 Collision col =
new Collision(k, m, maxCounts);
58 Tally statC =
new Tally(
"Statistics on collisions");
60 col.simulateRuns(n,
new MRG32k3a(), statC);
61 System.out.println(
"Total CPU time: " + timer.
format() +
"\n");
63 System.out.println(statC.
report(0.95, 3));
64 System.out.println (
"Theoretical mean: lambda = " + col.lambda +
"\n");
66 System.out.println(
"Counters:\n"
67 +
" c count Poisson expect.\n");
68 for (
int c = 0; c <= col.maxCounts; c++) {
69 System.out.printf(
" %2d %10d %12.1f%n", c, col.counts[c],
70 n * col.poisson.
prob(c));
Extends the class DiscreteDistributionInt for the Poisson distribution slaw00a (page 325) with mean.
double prob(int x)
Returns , the probability of .
Extends the abstract class RandomStreamBase by using as a backbone (or main) generator the combined m...
void setConfidenceIntervalStudent()
Indicates that a confidence interval on the true mean, based on the normality assumption,...
void init()
Initializes the statistical collector.
void add(double x)
Gives a new observation x to the statistical collector.
String report()
Returns a formatted string that contains a report on this probe.
String format()
Converts the CPU time used by the program since its last call to init for this AbstractChrono to a St...
The Chrono class extends the umontreal.ssj.util.AbstractChrono class and computes the CPU time for th...
This interface defines the basic structures to handle multiple streams of uniform (pseudo)random numb...