//
you're reading...
Uncategorized

Birthday Paradox: C++ Simulation

//pastebin.com/embed_js/UC7QNM8a

//pastebin.com/embed_iframe/UC7QNM8a

#include
#include
#include
using namespace std;

int main()
{
srand(time(0));
bool birthday [365] = {false};
bool done = false;
int count = 0;

while (!done) {
int next = rand() % 365;
count++;
if (birthday[next] == false)
birthday[next] = true;
else
done = true;
}
cout << "Count: " << count << endl;
}
[/code]

Advertisements

Discussion

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: