Skip to content

Instantly share code, notes, and snippets.

@hokamoto
Created November 9, 2019 13:37
Show Gist options
  • Save hokamoto/3853d9ebd59957d17d5b929c6787f2b0 to your computer and use it in GitHub Desktop.
Save hokamoto/3853d9ebd59957d17d5b929c6787f2b0 to your computer and use it in GitHub Desktop.
Generate a random number by RDRAND operation
#include <immintrin.h>
#include <stdio.h>
unsigned int rnd() {
unsigned int r = 0;
_rdrand32_step(&r);
return r;
}
int main() {
for(int i=0;i<100;i++) {
printf("%u\n", rnd());
}
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment