now on github:
https://github.com/DEShawResearch/Random123-Boost
Hi John,
I’ve also been working on a design and it will take another week before it’s good enough. It has similarities and differences (which is to be expected since we haven’t aligned). In short:
* a random_function concept which is a functor with operator()(input&,output&) or operator()(input&,output&,key&). I’ve considered returning a container but I prefer this.
template
class sha1_random_function
{
// type info
void operator()(input_type& _i, output_type& _o)
{
_sha1.reset();
_sha1.process_bytes(_i, input_traits::size );
_sha1.get_digest(_o);
};
private:
boost::uuids::detail::sha1 _sha1; // I found this inside boost!
};
* the input output are random access containers with acompanying traits that allow other components to store and interface with these input output. The traits are element type, number of elements and number of bits used per element. E.g. a uint_least32_t v[5]. Non of these container are stored inside the random function.
template <typename RandomFunction>
struct random_function_input_traits
{
typedef ... value_type; // the type of the elements in the input container
typedef... type; // the input container type
static const std::size_t size = ...; // the number of elements in the input container
static const std::size_t bits = ...; // the number of bits used from each element in the input container
};
* a generic counter_engine that turns a random_function into a random_engine using a counter. It has a template argument random_function and it stores and manipular a counter of type random_function::input and/or random_function::key and extract random Uint;s from the output buffer.
typedef counter_engine<
sha1_random_function<64>, // do a sha1 hash on a 64 bytes input buffer (256 bit)
boost::uint_least32_t, // return type of the random engine
32, // 32 random bits in the return type elements
32 // 32 bit seed
> sha1_counter;
* it doesn’t need to end with a counter_engine, other types of random engines adapters that do input manipulators besides a counter can be added.
My focus is mainly the counter_engine adaptor (which is finished), the random_function concept and its containers+traits. I have unfortunately limited time right now but I will analyse our designs and come back with ideas and feedback.