How do I generate random floats in C++?
I thought I could take the integer rand and divide it by something, would that be adequate enough?
How do I generate random floats in C++?
I thought I could take the integer rand and divide it by something, would that be adequate enough?
drand48(3)
is the POSIX standard way. GLibC also provides a reentrant version,drand48_r(3)
.The function was declared obsolete in SVID 3 but no adequate alternative was provided so IEEE Std 1003.1-2013 still includes it and has no notes that it's going anywhere anytime soon.
In Windows, the standard way is CryptGenRandom().
For C++, it can generate real float numbers within the range specified by
dist
variable