[llvm-bugs] [Bug 39209] New: std::uniform_int_distribution erroneously rejects generator values

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Oct 7 07:51:58 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=39209

            Bug ID: 39209
           Summary: std::uniform_int_distribution erroneously rejects
                    generator values
           Product: libc++
           Version: 6.0
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: llvm at christoph-conrads.name
                CC: llvm-bugs at lists.llvm.org, mclow.lists at gmail.com

Created attachment 20974
  --> https://bugs.llvm.org/attachment.cgi?id=20974&action=edit
Demonstration of bug

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

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20181007/57902c27/attachment.html>


More information about the llvm-bugs mailing list