1

Normally, I use the following lines to generate pseudo-random numbers in C++ code:

srand(time(0));
int x = rand() % 100; // 0 ~ 99

But since Intel has implemented random generator hardware in their new processors, I want to take advantage of the true 'randomness' from thermal fluctuations. I have searched Intel C++ compiler documents but didn't find a definitive guide on the RdRand API.

I looked at this post: True random numbers with C++11 and RDRAND

But it didn't show explicitly how to call this function in C++.

So my question is what compiler or library supports RdRand now and what's the C++ code template to call it.

Community
  • 1
  • 1
astr627
  • 13
  • 1
  • 4
  • Make sure you only call srand once per program. – Neil Kirk Mar 15 '15 at 01:11
  • I think `srand(time(0))` can be called multiple times to reseed the random number sequence. – astr627 Mar 15 '15 at 01:21
  • That's true. Sorry I didn't make my comment clear enough. I've seen examples of calling srand before every call to rand, so I thought that may be what you are doing here. – Neil Kirk Mar 15 '15 at 01:23

0 Answers0