I want to use a random-number-generator in c++ to make a maths quiz with randomly-generated numbers.
My problem is that using time(0)
is only accurate to a single second. In the IDE that I am using (NetBeans 8.2), a message appeared when hovering over srand(time(0))
with the message:
This is a weak random number generator; it is not useful for security purposes. Alternative: getrandom(void *buf,size_t buflen, unsigned int flags);/dev/urandom;
I could not find anything online about getrandom
. I was wondering if anyone could shed some light on the syntax of getrandom
? How to use it?
srand
only once, at the beginning of your program. But nowadays, there are better way of generating random number, such as therandom
standard library linked by @DanielJour. – Holt