random number generators for calc

tino ttk448 at gmail.com
Sun Dec 2 03:47:01 PST 2012


> of course it doesn't have fancy features like ranges or non-uniform
> distribution...

That's ok, I wouldn't use that against it, because these things are
independent. Any uniform int generator can easily be extended to
ranges, and uniform [0,1] distribution. And at least in theory, any
non-uniform distribution can then be generated using

 rand_some_non_uniform() = F_inv( rand_uniform01() );

where F_inv() is the inverse cdf (cumulative distribution function)
which in practice is not always easily available. Gnumeric has access
to the inverse cdf's through R. Boost also has them implemented
already (not as comprehensive as R though).

Btw, boost has the same structure, boost::mt19937 only generates
integers, and this forms the basis for all other distributions.

> ... looking at random.cxx it appears to use a MD5 hash to generate the
> random bytes; initialization is via seconds/nanoseconds of current time
> and thread-id.  since the cryptographic hash implementations in sal/rtl
> don't look heavily optimized this is likely not be the fastest way to
> generate random numbers, if that is a concern...

Speed is not my concern here (I guess parsing a cell is of an order of
magnitude slower?). My problem is with statistical properties, and
until somebody knows exactly what random.cxx does, I'd advice
against using it. I'm also no expert and I may well be wrong but an
MD5 based random number generator sounds a bit like a home made
generator where we don't even know if it's truly uniform distributed.

> We should not implement them in rtl/math.hxx until there are more users
> than calc's interpreter that need it. Lets not overcomplicate this stuff
> as long as it is not necessary.

What about implementation in random.cxx and creating random.hxx so all
the random stuff is in one place?

Tino



More information about the LibreOffice mailing list