Remix.run Logo
RandomOnyx 2 hours ago

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

jstanley 2 hours ago | parent [-]

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.

goalieca 2 hours ago | parent | next [-]

You should be using &0xFFFF for masking. Your mod is off by 1 too.

jstanley an hour ago | parent [-]

You're right, the code was correct but my comment above is wrong.

RandomOnyx 2 hours ago | parent | prev [-]

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