<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - Linear congruential generator generates invalid values"
   href="https://llvm.org/bugs/show_bug.cgi?id=27839">27839</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Linear congruential generator generates invalid values
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libc++
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>3.7
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>All Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>david.g.hammen@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, mclow.lists@gmail.com
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The linear congruential generator generates numbers outside the range of
`min()` and `max()` for some values of `a`, `c`, and `m`. For example,
`std::linear_congruential_engine <unsigned long long, 25214903917ull, 11ull,
1ull<<48 >` fails badly. These are the values used by `drand48`.


    #include <random>
    #include <iostream>
    #include <cstdint>

    using drand48_engine = std::linear_congruential_engine <
        std::uint64_t, 25214903917ull, 11ull, (1ull<<48) >;

    int main ()
    {
        drand48_engine rng;
        int pass_fail[2] = {0,0};

        for (int ii = 0; ii < 1000000; ++ii)
        {
            auto num = rng();
            ++pass_fail[num < (1ull<<48)];
        }
        std::cout << "#pass=" << pass_fail[1] << " #fail=" << pass_fail[0] <<
'\n';
    }</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>