random number generators for calc
tino
ttk448 at gmail.com
Wed Nov 28 10:00:33 PST 2012
> So, Michael Stahl commented in the bug that we do have our own
> random number generator function. One way is to just replace the
> direct call to rand() to this function instead. That should be very
> easy to do and I have no objection against it.
Just to be clear, I believe glibc's implementation of rand() is
excellent and doesn't need replacement unless one needs particular
statistical properties (the problem is only with windows rand()).
Boost offers generators I believe similar to glibc's rand() as well as
a few which have even better statistical properties but are slower.
The advantage of boost is that it includes transformations which lead
to all sorts of distributions ([0-1] uniform, normal, exponential ...).
This would allow for easy implementation of new functions like
RANDNORMAL(mu, sigma)
As for the bug report, if he's referring to
./core/sal/inc/rtl/random.h
then I can't see any function we can easily use for our purposes. It
seems to me all this does is generating and managing a random binary
array. From a quick look at the source it seems to use the
Wichmann-Hill algorithm, which apparently has a period of 16 million
(2^24) which is worse than glibc's rand().
Cheers, Tino
./core/sal/rtl/source/random.cxx
#define RTL_RANDOM_RNG(x, y, z) \
{ \
(x) = 170 * ((x) % 178) - 63 * ((x) / 178); \
if ((x) < 0) (x) += 30328L; \
\
(y) = 171 * ((y) % 177) - 2 * ((y) / 177); \
if ((y) < 0) (y) += 30269L; \
\
(z) = 172 * ((z) % 176) - 35 * ((z) / 176); \
if ((z) < 0) (z) += 30307L; \
}
More information about the LibreOffice
mailing list