std::map<unsigned int, std::string> table;
начните с этого.
unsigned int total(){
if(table.empty())
return 0;
return table.back().first;
}
void add_word(std::string word, unsigned int count){
unsigned current = total();
table[current+count]=word;
}
сейчас table
содержит карту из совокупного веса строки и все "до" ее до строки.
std::string pick( unsigned int x ){
return table.lower_bound(x).second;
}
выберите случайное число от 1
до total()
включительно. Вызовите pick(x)
, чтобы получить взвешенную строку вероятности.