Date: prev next · Thread: first prev next last
2012 Archives by date, by thread · List index


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){
   global_rng.seed(i);
}

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

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


Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.