Generating Pseudorandom FloatingPoint Valuesby Allen B. DowneyThis is a draft of a paper I think I will probably not publish, but I think it is kind of interesting, so I thought I would put it out there. If nothing else, it contains some pedagogical material about IEEE floatingpoint representation. Here is the paper in PDF, Compressed Postscript, and Postscript. And here is C code that implements several versions of my algorithm: AbstractThe conventional method for generating a pseudorandom floatingpoint value is to generate a pseudorandom integer and divide by a constant (using floatingpoint arithmetic). The problems with this approach are (1) the possible outcomes are a small subset of the representable floatingpoint values (about $7%$ for a typical implementation) and (2) subsequent transformation of these values may not yield the expected distributions (for example, applying a log transformation to numbers from a uniform distribution does not yield an exponential distribution as it would in real arithmetic). We present a new algorithm with the following properties: (1) it can produce every representable floatingpoint value in a given range, and (2) it is efficient in both time and use of pseudorandom bits.
