Tag Archives: Everyday Semi

IvyBridge RdRand


I heard that HW random number generator is implemented in Intel’s CPU since IvyBridge architecture. Today I tried to use it.

How to use?

We can directly access rdrand instruction through assembler but it is easy to use intrinsics offered by the header immintrin.h. The header is same one as AVX intrinsics. For obtaining uniform double random number in the range of [0, 1], we can use the following simple code:


Speed test vs. Mersenne twister

This article says rdrand is capable of 7000M instructions / seconds. How fast is it? I compared the speed to MT(std::random implementation) in a simple experiment. Test code:

Execution time (executed in i7-3517U):

  • MT : 0.421 seconds
  • RdRand : 1.322 secods

Trace paths!!

I added simple modification to smallpt (simply replacing erand48 to the above rdrand function). The source is here. And comparison with MT version (note that erand48 is not used in Windows so I used std::random one instead). Source: MT version and rdrand version.

Execution time:

  • MT : 89.107 seconds
  • RdRand : 100.53 seconds


Seems no difference.