#include #include using namespace std; struct Outcome { double selections; double success; double coverage; }; Outcome collect(unsigned int n, unsigned long trials=1, unsigned int limit=UINT_MAX) { Outcome result; result.selections = 0; result.coverage = 0; result.success = 0; for (unsigned int t=0; t < trials; t++) { unsigned int count = 0; unsigned int marks = 0; vector used(n, false); while (count < limit && marks < n) { count++; int pick = rand() % n; // will be from 0 to n-1 if (!used[pick]) { used[pick] = true; marks++; } } result.selections += count; result.coverage += marks; if (marks == n) result.success++; } result.selections /= trials; result.success /= trials; result.coverage /= trials; return result; }