mercredi 30 novembre 2016

How can I use Linux getrandom system call to generate a random number within a range?

I have the following piece of code

#include <unistd.h>
#include <sys/syscall.h>
#include <linux/random.h>

unsigned long int s;
syscall(SYS_getrandom, &s, sizeof(unsigned long int), 1);
std::cout << s << std::endl;

According to GETRANDOM(2) it returns random numbers from /dev/random or /dev/urandom with high entropy.

How can I use it to return numbers within a range? The range I'm using is [0 - 2^125]




Aucun commentaire:

Enregistrer un commentaire