我如何使用Linux getrandom系统调用在一个范围内生成一个随机数字?(How can I use Linux getrandom system call to generate a random number within a range?)
我有以下一段代码
#include
#include
#include
unsigned long int s;
syscall(SYS_getrandom, &s, sizeof(unsigned long int), 1);
std::cout << s << std::endl;
根据GETRANDOM(2),它从/ dev / random或/ dev / urandom返回高熵的随机数。
我怎样才能使用它来返回范围内的数字? 我使用的范围是[0 - 2 ^ 125] [0 - 125 ^ 2]
I have the following piece of code
#include
#include
#include
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