‹ BackHN Continuity

Thread

AMD's random number generator can't generate a 0?

288 points · 220 comments · BruceEel

  1. jstanley · · focus · HN ↗
    This is not the first RNG bug on Zen 2, I recall after I first got mine that some application or other would quit immediately at startup because rdrand always returned -1, i.e. all 1s. It was fixed with a microcode update.

    Do we now learn that they fixed "always generate all 1s" with "never generate all 0s"??

    EDIT: I've been unable to reproduce the problem on my CPU, FWIW. It's a Ryzen 5 3600.

    EDIT2: OK, update, I can reproduce it with rdrand16, rdrand32 is fine but rdrand16 can never generate all 0s. So my CPU does have this problem!

    1. RandomOnyx · · focus · HN ↗
      Does rdrand32 and then taking the lowest 16 bits of its result yield any zeroes?

      Basically I'm wondering if it's a bug in the version of the instruction that writes to a 16-bit reg, or a bug in the underlying RNG

      1. jstanley · · focus · HN ↗
        Yes it does. rdrand32()%65535 was my first attempt, and generated zeroes at about the expected rate, that's why I initially erroneously thought my CPU did not have this problem.
        1. RandomOnyx · · focus · HN ↗
          How about* rdrand32()%65536? Taking the remainder by 65535 doesn't take the lowest 16 bits after all

          *: missed a word the first time around

Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.