http://www.velocityreviews.com/forums/(E-Mail Removed) wrote :

> On Apr 7, 5:41 am, Francois Grieu <(E-Mail Removed)> wrote:

>> Hi,

>>

>> suppose I have an unsigned 32-bit type tu32 and a robust

>> 32-bit Random Number Generator

>> tu32 rng32(void);

>> producing output uniformly distributed on [0 .. 0xFFFFFFFF].

>>

>> I want to build a robust double RNG with output uniformly

>> distributed on ]0..1[ (or similar but known, e.g.

>> [DBL_MIN..1-DBL_EPSILON] ), for some sound definition of

>> uniformly distributed matching what double allows.

>> double rngdouble(void);

>> In particular, I do care that even a subsample of the output

>> restricted to some interval like [0 .. 1e-7] appear uniform

>> rather than "grainy".

>

>

> I want to point out that the values you can actually put in a double

> are not uniformly distributed, so you need to clarify exactly what you

> mean by that.
I simply want the result to behave as close to a uniform random

variable over the interval 0..1 as allowed by double; or nearly as

close.

> But let's say you want to generate numbers from

> [0..1,000,000) at .001 steps (acknowledging that this will not

> generate exact floating point values for the usual reasons).
Rather, say that I am interested in simulating the quantity

-log(v) where v is a uniform random variable over 0..1

[This models in particular the delay between events occurring

randomly if there is one event per time unit on average]

> Generate good quality random integer of at least 30 bits, discard

> any values larger than or equal to the biggest multiple of

> 1,000,000,000 smaller than the maximum random number your source

> will generate (for example if your source produces a 32 bit unsigned,

> discard any values larger than 3,999,999,999 (and if you discard,

> you need to generate a new value). Mod that by 1,000,000,000,

> and scale the result to your output range.
If I make an rngdouble() according to this principle and plots

the value -log(rngdouble()) some 10e11 times on a linear scale from

0 to 25, there will be a distinctive pattern on the upper end,

which is due only to a defect of the implementation of rngdouble(),

and not at all on a limitation of double.

Francois Grieu