Skip to content

Instantly share code, notes, and snippets.

@thypon thypon/wheel.cpp
Created Sep 29, 2015

Embed
What would you like to do?
wheel extraction
#include <tuple>
#include <list>
#include <string>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <thread>
#define ENTRY pair<string, unsigned int>
#define LABEL 0
#define WEIGHT 1
using namespace std;
int main(int argc, char const *argv[]) {
list<ENTRY> l;
int weight, max = 0;
string label;
srand(time(0));
for (cin >> weight; weight > 0; cin >> weight) {
max += weight;
cin >> label;
l.push_back(make_pair(label, weight));
}
int extract = rand() % max + 1;
cout << extract << endl;
list<ENTRY>::iterator it = l.begin();
extract -= get<WEIGHT>(*it);
while (extract > 0) {
extract -= get<WEIGHT>(* ++it);
}
cout << get<LABEL>(*it) << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.