How can I get a random float value from /dev/urandom
?
If I simply use a cast, by saying:
int fd = ::open("/dev/urandom", O_RDONLY);
uint32_t n;
read(fd, &n, sizeof(n));
float f = n;
...I'm not sure if I have a guarantee of portability, because I don't know if large values of n
will necessarily be representable as f
? Is MAXUINT guaranteed to be representable as a float
?