4 #include <system_error> 6 #include <linux/random.h> 7 #include <sys/syscall.h> 13 static long getrandom(
void* buf, std::size_t buf_len,
unsigned int flags)
15 return syscall(SYS_getrandom, buf, buf_len, 0);
18 void random_fill(
char* begin,
char* end)
22 long bytes_read = getrandom(begin, end - begin, 0);
28 else if (errno == EINTR)
34 throw std::system_error(errno, std::system_category());