Skip to content

SRandom API may return the same member of the set if input argument "count" is positive #14

Description

@loadwiki

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--;

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions