If k is set to zero,then the wile statement will be pass and idx_flag[0] will be set to 1;
If k is set to zero the second time, idx_flag[0] will be set to 2;
The first member of set will be return twice in the case above.
Further more , the biggest member will be returned with higher probability if the rand() function return the same value.
//......
int k = rand() % remain_card + 1;
int i = 0;
int cnt = 0; // the valid k-th number
while (i < card && cnt < k) {
if (idx_flag.find(i) == idx_flag.end()) {
cnt++;
}
if (cnt == k) break;
i++;
}
idx_flag[i]++;
remain_card--;
If k is set to zero,then the wile statement will be pass and idx_flag[0] will be set to 1;
If k is set to zero the second time, idx_flag[0] will be set to 2;
The first member of set will be return twice in the case above.
Further more , the biggest member will be returned with higher probability if the rand() function return the same value.
//......
int k = rand() % remain_card + 1;
int i = 0;
int cnt = 0; // the valid k-th number
while (i < card && cnt < k) {
if (idx_flag.find(i) == idx_flag.end()) {
cnt++;
}