https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100444

            Bug ID: 100444
           Summary: std::random_device isn't random on AMD
           Product: gcc
           Version: 10.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ecree429 at virginmedia dot com
  Target Milestone: ---

On certain AMD processors (in my case Ryzen 5 3600, stepping 0, microcode
0x8701013), RDRAND instruction is broken and always returns all-1s.  Thus e.g.
    #include <iostream>
    #include <random>

    int main(void)
    {
      static std::random_device rd;
      std::cout << rd() << '\n';
    }
always prints 4294967295.

Other RNG implementations such as Qt's QRandomGenerator detect this brokenness
and work around it, falling back to an alternate source of entropy.  libstdc++
should ideally do the same, rather than silently failing to be random.

Reply via email to