For generating random doubles, there is drand48, but
These functions are declared obsolete by SVID 3, which states that
rand(3) should be used instead.
How do I construct my random double with drand48? On a side note, the
random float?
Simply concatenating two int from rand() and casting may lead to
NaN, which is not acceptable. I’d like to avoid using only 32 random
bits for a double.
This citation of an obsolete standard in the man pages for linux is unfortunate. If I see correctly SVID 3 was published 1986, and obsoleted itself since long. POSIX has this family of functions and there are no plans to phase them out.
But if you are at it, consider to use
erand48instead ofdrand48. It has the advantage that you provide it with a seed state yourself. By that it is reentrant, generally behaves better if you use it in a threaded environment (and initialize the seeds for threads differently) or is deterministic if you need it for reproducible simulations.The only little thing is that you have to have in mind is that it only gives you 48 bits of pseudo-randomness. Usual
doublearithmetic is with 52 bit, so be careful that you don’t use the lowest 4 bits, they are no good.