random number generators for calc

tino ttk448 at gmail.com
Sat Dec 1 03:22:09 PST 2012

> the header is sal/inc/rtl/random.h (which is apparently a C interface).

Exactly, the C++ interface is missing. Also, the source doesn't have
any comments to say what algorithm is implemented etc. Do you know?
> but why do we need a wrapper around boost in sal?  i mean i haven't
> looked at the boost random stuff but unless its interface is horrible
> (always a possibility with boost i guess) _and_ there are multiple
> places where we'd want to call it, then why not use it directly from
> Calc's formula implementation?

I guess that's for someone more experienced to comment on. My simple
reason was rtl::math seems a good collection of maths functions this
may fit in, and there's no decision yet if RANDNORMAL() etc should be
implemented in sc or scaddins (or at all?).

The boost code would look something like this:

#include <boost/random.hpp>

// the underlying random number generator as global variable
// using Mersenne twister algorithm
#define BOOST_RNG_ALGO  boost::mt19937
BOOST_RNG_ALGO global_rng;

// set initial state of generator
void rand_set(int i){

// rand from a discrete uniform (same as RANDBETWEEN())
int rand_uniform_int(int from, int to){
   static boost::variate_generator<BOOST_RNG_ALGO&,
                     boost::random::uniform_int_distribution<> >
   return myrand();

// rand from a Chi-squared Chi^2(k) distribution
double rand_chisq(int k) {
   static boost::variate_generator<BOOST_RNG_ALGO&,
                     boost::random::chi_squared_distribution<> >
   return myrand();

More information about the LibreOffice mailing list