Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- #include <cstdlib>
- #include <ctime>
- #include <random>
- using namespace std;
- int main()
- {
- srand(time(NULL)); // Seed - the specific number used to generate random numbers - change to get different results
- srand(rand());
- //Variable setup
- double nDeck = 52; //Size of deck
- int kCards = 10; //Amount of cards picked
- int dataSize = 1000000; //Amount of times simulation is run
- int playerCards[kCards]; //Arrangement of player's cards
- int houseCards[kCards]; //Arrangement of house's cards
- int trial[dataSize]; //Stores the amount of matches for each trial
- double totalMatches[kCards+1]; //Stores the amount of matches for each specific case
- int pick = 0; // card picked
- int matches = 0; // amount of matches in a speccific situation
- for (int i = 0; i < kCards; i++) //Required for checking repeats
- {
- playerCards[i] = 0;
- houseCards[i] = 0;
- totalMatches[i] = 0;
- }
- totalMatches[10] = 0;
- default_random_engine generator; // uniform random number generation
- uniform_real_distribution<double> distribution(0.0, nDeck);
- //uniform_int_distribution<int> distribution(0, nDeck);
- for (int r = 0; r < dataSize; r++) //Start of simulation
- {
- for (int i = 0; i < kCards; i++) //Picking cards for the house
- {
- pick = (rand() % 52) + 1; //Random card picked
- //pick = (int) distribution(generator);
- for(int o = 0; o < kCards; o++) //Checking that the card was not picked before
- {
- if (pick == houseCards[o])
- {
- i--; // This value was invalid, find another value
- break; // Was a repeat, find another random value
- }
- }
- houseCards[i] = pick;
- }
- for (int i = 0; i < kCards; i++) //Picking cards for the player
- {
- pick = rand() % 52 + 1; //Random card picked
- // pick = (int) distribution(generator);
- for(int o = 0; o < kCards; o++) //Checking that the card was not picked before
- {
- if (pick == playerCards[o])
- {
- i--; // This value was invalid, find another value
- break; // Was a repeat, find another random value
- }
- }
- playerCards[i] = pick;
- }
- for(int k = 0; k < kCards; k++)// Compare all of the house's and player's cards to check for any matches
- {
- for(int l = 0; l < kCards; l++)
- {
- if (houseCards[k] == playerCards[l])
- {
- matches++;
- }
- }
- }
- trial[r] = matches;
- matches = 0;
- }
- int temp = 0;
- for (int i = 0; i < dataSize; i++) // Adds each individual trial to count the total amount of matches
- {
- temp = trial[i]; // temp must be used for g++ compiler
- temp =totalMatches[temp]+1;
- totalMatches[ trial[i] ] = temp;
- }
- for (int i = 0; i < kCards + 1; i++) //Output of the results
- {
- cout << "Matches of " << i << "'s: " << totalMatches[i] << "." << endl;
- }
- cout << endl;
- double temp2 = 0.0000001; // For the probability of the outcome
- double temp3 = 0;
- for (int i = 0; i < kCards + 1; i++) // probability of outcome
- {
- temp2 = 100*(totalMatches[i]/dataSize);
- cout << "Probability for matches of " << i << "'s: " << temp2 << " %" << endl;
- temp3 += temp2;
- }
- cout << "Total Percentage: " << temp3 << endl;
- return 0;
- }
- //in the case of 52 cards and select 10
- //0: .09301 3 USD 09.301%
- //1: .28185 0 USD 28.185%
- //2: .33574 0 USD 33.574%
- //3: .20464 0 USD 20.464%
- //4: .06963 3 USD 06.963%
- //5: .01355 10 USD 01.355%
- //6: .00149 100 USD 00.149%
- //7: .00009 1,000 USD 00.009%
- //8: <.00001 10,000 USD 00.001%
- //9: <.00001 100,000 USD 00.001%
- //10: <.00001 1,000,000 USD 00.001%
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement