Last active
September 27, 2018 01:39
-
-
Save bwedding/79bcfe05b634c58d0bd05c60e6657f75 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
#include <algorithm> | |
#include <functional> | |
#include <iostream> | |
#include <random> | |
#include <map> | |
// Percentage of pickers in each group | |
enum group {low, lowMid, hiMid, hi}; | |
// Change these percentages to make more people pick high, low or in the middle | |
std::map<enum group, double> groups = | |
{ | |
{ low, 0.05}, | |
{ lowMid, 0.15 }, | |
{ hiMid, 0.30 }, | |
{ hi, 0.50 }, | |
}; | |
using distPtr = std::uniform_int_distribution<long>; | |
int main() | |
{ | |
std::mt19937_64 gen{ std::random_device{}() }; | |
// The values define the range of numbers each group picks from | |
// For example, the low group, now set to 5% of the people, will | |
// choose values from 1 to 100,000. The high group, set to 50% of | |
// the pickers, will choose numbers from 700,001 to 999,999 | |
std::uniform_int_distribution<long> lowDist { 1,100000 }; | |
std::uniform_int_distribution<long> lowMidDist { 100001,300000 }; | |
std::uniform_int_distribution<long> hiMidDist { 300001,700000 }; | |
std::uniform_int_distribution<long> hiDist { 700001,999999 }; | |
distPtr *curDist[] = { &lowDist, &lowMidDist, &hiMidDist, &hiDist }; | |
std::vector<bool> Picked; | |
// Initialize the picker to all false | |
Picked.resize(1000000, false); | |
int j = 0; | |
for (auto val : groups) | |
{ | |
std::cout << val.second << std::endl; | |
double PickerPercent = val.second; | |
int numPickers = 999999 * PickerPercent; | |
std::cout << "Picking for " << numPickers << std::endl; | |
std::cout << curDist[j]->a() << ", " << curDist[j]->b() << std::endl; | |
for (int i = 0; i < numPickers; i++) | |
{ | |
Picked[(*curDist[j])(gen)] = true; | |
} | |
j++; | |
} | |
long choice = 0; | |
while(choice != 1) | |
{ | |
std::cout << "Pick a number between 1 and 999999\n Pick 1 to quit.\n"; | |
std::cin >> choice; | |
std::cout << "You picked a " << (Picked[choice] ? "dud!" : "Winner!") << std::endl; | |
} | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment