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: unassignedclangb...@nondot.org
          Reporter: l...@christoph-conrads.name
                CC: llvm-bugs@lists.llvm.org, mclow.li...@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to