Boost logo

Boost Users :

Subject: Re: [Boost-users] [random] Poisson generator
From: Stefan Strasser (strasser_at_[hidden])
Date: 2009-09-14 08:52:47


Am Monday 14 September 2009 17:30:58 schrieb Steven Watanabe:
> AMDG
>
> Stefan Strasser wrote:
> > a little OT: is there a random number generator in boost.random that is
> > comparable to rand()?
> > I recently needed some low-quality random numbers, and every random
> > number generated in boost.random I tried was way too slow, slower than
> > the alternative I tried to avoid by using random numbers (a mutex lock).
> > so I ended up writing an own rand() function, as C rand() has global
> > state so it can't be used from multiple threads.
>
> There are several linear congruential generators:
> minstd_rand0, minstd_rand, and rand48 all
> defined in boost/random/linear_congruential.hpp
>

I tried minstd_rand. iirc about 30 times slower than rand() and several times
a mutex lock. I realise that rand() is a...unsophisticated random number
generator in most implementations, if you can even call it that. but it's
still enough for some use cases and there is no thread safe version of it in
the C(++) standard.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net