AMDG On 04/29/2014 10:00 AM, John Salmon wrote:
I've dusted off the code I wrote a couple of years ago and republished it, now on github:
For this to be included in Boost.Random, it must be released under the Boost Software License.
<snip>
CBRNGs overcome all these problems. With CBRNGs, the code looks like this (see libs/random/examples/counter_based_example.cpp for a fully worked example):
using namespace boost::random; typedef threefry<4, uint32_t> Prf; normal_distribution nd; Prf::key_type key = {seed}; Prf prf(key); // seed may come from command line for(size_t i=0; i
Is there a good reason why this shouldn't be written as: for(...) { ... std::seed_seq s{ seed, atoms[i].id, timestep, THERMALIZE_CTXT }; counter_based_engine<Prf> cbrng(s); ... } I don't really like making the details of the algorithm (i.e. key and domain) part of the primary interface.
Let's consider the code changes between the two fragments:
<snip>
- Since it models a URNG, cbrng can be passed as an argument to the normal_distribution, nd. In order to make each atom independent,
nd.reset()
is called each time through the loop.
<snip>
FWIW, I don't really think that reset was a good idea in the first place, and it's currently a no-op in all distributions. To run the loop in parallel, you'd need to make a copy of nd in every thread, anyway.
counter_based_urng ------------------
The counter_based_urng class uses the pseudo-random property of PRFs to perform random number generation in accordance with the requirements of a UniformRandomNumberGenerator. <snip>
counter_based_engine --------------------
The counter_based_engine class is a templated adapter class that models a bona fide RandomNumberEngine. <snip>
Is there really a good reason to make two separate templates? A RandomNumberEngine is a URNG, by definition. In Christ, Steven Watanabe