random number generators for calc
markus.mohrhard at googlemail.com
Sun Dec 2 07:06:32 PST 2012
On Sun, Dec 02, 2012 at 11:47:01AM +0000, tino wrote:
> > ... 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?).
Speed has to be nearly always a concern in calc core. We don't parse the
cell formula for each evaluation. We have an intermediate format that is
extremely fast to evaluate and we have to be very careful that we are
not introducing more performance regressions. For a single cell this
seems not important but on a sheet with thousand of depending cells it
is quite important that a function is not slower than necessary.
> 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.
Well in most cases the statistical properties of a random function will
not matter in Libreoffice. I agree that it is different in Calc and
seeing that the rand() function in Windows is suboptimal we should think
about a solution for Calc's RANDOM function.
> > 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?
Why do you want this abstraction? Following KISS I would just start
implementing the functions in ScInterpreter and extract commonly used
parts into an own method. If at some point other parts of Libreoffice
also need random functions with known statistical properties we can
still extract them.
More information about the LibreOffice