Skip to content

std::uniform_int_distribution erroneously rejects generator values #38557

@llvmbot

Description

@llvmbot
Bugzilla Link 39209
Version 6.0
OS All
Attachments Demonstration of bug
Reporter LLVM Bugzilla Contributor
CC @mclow

Extended Description

Given a generator returning values in the interval [0, r] and std::uniform_int_distribution(0, b), let r,b such that r+1 multiple of b+1. In this case std::uniform_int_distribution may erroneously reject generator values although no rejection sampling is needed.

In the demonstration program in the attachment, r=19, b=9 so that half of all generator values are rejected. The bug does not occur if r+1 and b+1 are powers of two.

Note that the GNU C++ Library contains a similar bug:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80977

$ clang++ --version
clang version 6.0.1 (tags/RELEASE_601/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm/6/bin

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillalibc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.random

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions