random number generators for calc

tino ttk448 at gmail.com
Tue Dec 4 02:37:58 PST 2012


> > 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.

I'm happy to propose a patch this way. Just need to be aware that
RANDBETWEEN() which is part of scaddins would also need a replacement
of rand().

Also, another consideration is the way to implement different
non-uniform distribution, just wondering if anyone has a strong
view on this:

(1) implementation similar to rand() and srand(), where the state of
the generator is saved in a global variable (which is not exposed via
a header file and can only be changed by srand), and all other
non-uniform generators draw from the same rand(). this requires an
srand() call ideally at the start of libreoffice or calc, currently
done in
 ./sc/source/core/data/global.cxx

(2) each rand_nonuniform() function draws from it's own private rand()
generator with its own state, which is defined as a static variable
and initialised at the first call.


For a general purpose library one would probably do (1) (or (1) and
encapsulated in a class) but for calc both versions are fine in my
opinion. Memory requirements for boost::mt19937 is
625*sizeof(uint32_t) so I guess even if we had 10 copies (one for each
non-uniform rand) of it that wouldn't be a problem?



More information about the LibreOffice mailing list